CentOS 7.2环境搭建实录(第四章:python环境配置)

发布时间:2019-06-08 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了CentOS 7.2环境搭建实录(第四章:python环境配置)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

第四章:python环境配置

使用环境工具

python 环境工具
python            2.7.5  # python2版本,系统自带
pip               9.0.1  # python2版本的pippython工具集,编译安装
virtualenv        15.1.0 # python2版本虚拟环境依赖,pip安装
virtualenvwrapPEr 4.8.2  # 配合virtualenvwrapper使用,pip安装
SETUPtools        38.5.1 # python工具集,编译安装
gunicorn          19.7.1 # pythonwsgi服务器pip安装
supervisor        3.3.4  # python进程管理工具,pip安装

python3 环境工具
python3           3.6.4  # python3版本,编译安装  
pip               9.0.1  # 安装python3版本自带,区别于python2环境下的pip
setuptools        28.8.0 # 安装python3版本自带
gunicorn          19.7.1 # pythonwsgi服务器,pip安装

其他工具
gIT               1.8.3.1 # 著名软件托管平台

配置python环境工具

简单说明

CentOS 7.2服务器自带python2.7.5版本,可惜没有pip工具,所以我们需要先安装
pip工具,然后在此基础上一步步搭建pythonweb开发环境    

编译安装pip

cd /usr/local/src
wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486DF43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
tar -zxvf pip-9.0.1.tar.gz
cd pip-9.0.1/
python setup.py build
python setup.py install
pip -V # 查看安装是否成功

编译安装setuptools

cd /usr/local/src
wget https://pypi.python.org/packages/6c/54/f7e9cea6897636a04e74c3954f0d8335cc38f7d01e27eec98026b049a300/setuptools-38.5.1.zip#md5=1705ae74b04d1637f604c336bb565720
yum install zip # 已经安装的同学跳过这步
unzip setuptools-38.5.1.zip
cd setuptools-38.5.1
python setup.py build
python setup.py install
pip list # 查看setuptools是否安装成功

备注:如果执行pip list命令时出现
DEPRECATION: The default format will switch to columns in the Future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
错误,解决方法如下:
vi /root/.pip/pip.conf
输入:
[list]
format=columns
保存退出即可

安装git

yum install git
关于git的基本操作我就不在这里叙述了,最后我会放一篇资料提供给大家参考

shell显示git状态

vi /etc/profile
# 插入下方代码
source /usr/share/doc/git-1.8.3.1/contrib/completion/git-completion.bash
source /usr/share/doc/git-1.8.3.1/contrib/completion/git-prompt.sh
export GIT_ps1_SHOWDIRTYstatE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREam="verbose git svn"
PS1='[u@h W$(__git_ps1 " (%s)")]$ '
source /etc/profile

安装virtualenv virtualenvwrapper

pip install virtualenv virtualenvwrapper
# 配置环境变量
vi /etc/profile
# 输入下列代码:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/workspace
source /usr/local/bin/virtualenvwrapper.sh
# 保存退出:
source /etc/profile

安装gunicorn

pip install gunicorn

安装supervisor

pip install supervisor

supervisor配置修改

cd /etc/
mkdir supervisor
cd supervisor
mkdir conf.d
echo_supervisord_conf
vi supervisord.conf
# 修改配置如下:

CentOS 7.2环境搭建实录(第四章:python环境配置)


CentOS 7.2环境搭建实录(第四章:python环境配置)

# 保存退出
# 开启supervisord
supervisord -c /etc/supervisor/supervisord.conf
ps aux|grep supervisord

CentOS 7.2环境搭建实录(第四章:python环境配置)

# 启动成功

# 在浏览器使用域名:9001,输入设置的账号,密码结果如下

@H_932_512@

# 不用在意上面的blog项目,下一章会讲

配置supervisor开机启动

cd /lib/systemd/System/
touch supervisord.service
#加入下列代码:

# supervisord service for systemd (CentOS 7.0+)
# by ET-CS (https://github.COM/ET-CS)
[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

# 保存退出
# 尝试如下命令
systemctl stop supervisord.service
systemctl start supervisord.service
systemctl restart supervisord.service

环境安装结果如下

CentOS 7.2环境搭建实录(第四章:python环境配置)

配置python3环境工具

安装python3

cd /usr/local/src
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
tar -zxvf Python-3.6.4.tgz
cd Python-3.6.4/
./configure --prefix=/usr/local/python3
make && make install
安装成功
python3安装自带pip和setuptools

配置python3环境变量

vi /etc/profile
export PATH=$PATH:$HOME/bin:/usr/local/python3/bin
source /etc/profile

安装gunicorn

piP3 install gunicorn

环境安装结果如下

CentOS 7.2环境搭建实录(第四章:python环境配置)

其他文章
第一章:环境配置和nginx安装
第二章:php安装
第三章:mysql安装和postgresql安装

相关链接:
Git教程
supervisor开机启动配置

脚本宝典总结

以上是脚本宝典为你收集整理的CentOS 7.2环境搭建实录(第四章:python环境配置)全部内容,希望文章能够帮你解决CentOS 7.2环境搭建实录(第四章:python环境配置)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。