CentOS 7.2環境搭建實錄(第四章:python環境配置)

第四章:python環境配置

使用環境工具php

python 環境工具
python            2.7.5  # python2版本,系統自帶
pip               9.0.1  # python2版本的pip,python工具集,編譯安裝
virtualenv        15.1.0 # python2版本虛擬環境依賴,pip安裝
virtualenvwrapper 4.8.2  # 配合virtualenvwrapper使用,pip安裝
setuptools        38.5.1 # python工具集,編譯安裝
gunicorn          19.7.1 # python的wsgi服務器,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 # python的wsgi服務器,pip安裝

其餘工具
git               1.8.3.1 # 著名軟件託管平臺

配置python環境工具

簡單說明python

CentOS 7.2服務器自帶python2.7.5版本,惋惜沒有pip工具,因此咱們須要先安裝
pip工具,而後在此基礎上一步步搭建python的web開發環境

編譯安裝pipmysql

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 # 查看安裝是否成功

編譯安裝setuptoolsnginx

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
保存退出便可

安裝gitgit

yum install git
關於git的基本操做我就不在這裏敘述了,最後我會放一篇資料提供給你們參考

shell顯示git狀態github

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 virtualenvwrapperweb

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

安裝gunicornsql

pip install gunicorn

安裝supervisorshell

pip install supervisor

supervisor配置修改segmentfault

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

clipboard.png
clipboard.png

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

clipboard.png

# 啓動成功

# 在瀏覽器使用域名:9001,輸入設置的帳號,密碼結果以下

clipboard.png

# 不用在乎上面的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

環境安裝結果以下
clipboard.png

配置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

環境安裝結果以下
clipboard.png

其餘文章:
第一章:環境配置和nginx安裝
第二章:php安裝
第三章:mysql安裝和postgresql安裝

相關連接:
Git教程
supervisor開機啓動配置

相關文章
相關標籤/搜索