<title>CentOS Upgrade Python2.7 and install Pip</title> CentOS Upgrade Python2.7 and install PIP1) upgrade Python2.7?
1234567891011121314151617181920212223242526272829303132 |
python -V? # 查看版本:Python
2.6
.
6 ?mkdir -p ~/Env/python; cd ~/Env/python? # 创建个目录 ?wget --no-check-certificate https:
//www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar Jxvf Python-
2.7
.
6
.tar.xz
cd Python-
2.7
.
6
./configure --prefix=/usr/local/py-
2.7
.
6 ?#
"./configure -h"
查看帮助
make? # 报模块缺失时,有需要的安装后重make
# issue: INFO: Can‘t locate Tcl/Tk libs and/or headers
#??????? Python build finished, but the necessary bits to build these modules were not found:
#??????? ...
# 注
1
:zlib必要,之后安装setuptools要用。见
"安装setuptools"
。
# 注
2
:openssl必要,之后pip要用。见
"安装pip"
。
# 注
3
:bzip2也最好加,执行
"yum install bzip2 bzip2-devel -y"
。
make install ?# 建立软链接,默认指向Python2.
7
mv /usr/bin/python /usr/bin/python2.
6.6
ln -s /usr/local/py-
2.7
.
6
/bin/python2.
7 /usr/bin/python
python -V? # Python
2.7
.
6 ?# yum不兼容Python2.
7
,需要指定为原版本
vi /usr/bin/yum
# 将
"!/usr/bin/python"
改为
"!/usr/bin/python2.6.6" ?# ibus也不兼容Python2.
7
,需要修改
# 将
"exec python"
改为
"exec python2.6.6"
ll /usr/bin | grep python? # 确认下python2.
6.6
vi /usr/bin/ibus-setup? # 修改
vi /usr/libexec/ibus-ui-gtk? # 修改
reboot? # 可能需要重启
|
2) Prepare the Base environment 2.1) Install Setuptools
?
1234567891011121314151617181920212223242526 |
cd ~/Env/python ?wget http:
//pypi.douban.com/packages/source/s/setuptools/setuptools-3.3.tar.gz? # 豆瓣源
tar zxvf setuptools-
3.3
.tar.gz
cd setuptools-
3.3
python setup.py build
sudo python setup.py install
# 或者用ez_setup.py,同样改为豆瓣源
# wget https:
//bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
# python ez_setup.py --download-base http:
//pypi.douban.com/packages/source/s/setuptools/ ?# 缺少zlib,安装setuptools时出错。
# issue: RuntimeError: Compression requires the (missing) zlib module
yum install zlib zlib-devel -y
# 重make Python2.
7
再安装
cd ../Python-
2.7
.
6
make? # 这时才注意先前make时缺了好多模块
make install ?# 环境变量
vi /etc/profile
# 添加如下内容:
# PY_HOME=/usr/local/py-
2.7
.
6
# export PATH=$PY_HOME/bin:$PATH
source /etc/profile? # 当前终端生效,reboot后才会完全生效
echo $PATH
|
2.2) Install Pip
?
1234567891011121314 |
easy_install -i http: //pypi.douban.com/simple pip ?# 缺少ssl模块,pip使用时出错 # issue: ImportError: cannot import name HTTPSHandler yum install openssl openssl-devel -y make? # Python- 2.7 . 6 目录 make install ?# 配置pip为豆瓣源 mkdir ~/.pip? # ls或ll -a 查看隐藏内容 vi ~/.pip/pip.conf # 添加如下内容: # [global] # index-url = http: //pypi.douban.com/simple |
2.3) Install Virtualenv
?
123 |
su pip install virtualenv pip install virtualenvwrapper |
Virtualenv is used to create an isolated Python runtime environment, which avoids confusion when it relies on different libraries and versions.
The Virtualenvwrapper provides more convenient commands for extensions on the virtualenv.
2.4) Other document
Network
- Twisted
- ' Pip install Twisted '
- Zope.interface
- Scrapy
Web Framework
From for notes (Wiz)
CentOS Upgrade Python2.7 and install Pip