天天看點

python更新pip_python版本更新及pip部署方法

Python版本更新

CentOS 6.3自帶的Python版本為2.6,首先需要更新到2.7版本。由于舊版本的Python已被深度依賴,是以不能解除安裝原有的Python,隻能全新安裝。

1.下載下傳Python-2.7.4.tgz

wget http://python.org/ftp/python/2.7.4/Python-2.7.4.tgz

2. 解壓安裝,指令如下:

1 tar -xvf Python-2.7.4.tgz

2 cd Python-2.7.4

3 ./configure --prefix=/usr/local/python2.7

4 make

5 make install

3. 建立連結來使系統預設python變為python2.7

mv /usr/bin/python /usr/bin/python.old

ln-s /usr/local/python2.7/bin/python2.7 /usr/bin/python

4. 檢視Python版本

python –V

5. 修改yum配置(否則yum無法正常運作)

vim /usr/bin/yum

将第一行的#!/usr/bin/python修改為系統原有的python版本位址#!/usr/bin/python2.6

至此CentOS6.3系統Python已成功更新至2.7.4版本

安裝pip

Pip是一個安裝和管理python包的工具。

安裝方法如下:

1. 下載下傳pip,位址 https://bootstrap.pypa.io/get-pip.py

2. 執行安裝指令

yum install setuptool zlib* -y

pythonget-pip.py

3. 建立連接配接(否則會報錯提示“指令不存在”)

ln -s /usr/local/python2.7/bin/pip /usr/bin/pip

測試:

[[email protected] ~]# pip install redis

Collecting redis/usr/local/python2.7/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

InsecurePlatformWarning

Downloading redis-2.10.5-py2.py3-none-any.whl (60kB)100% |################################| 61kB 759kB/s

Installing collected packages: redis

Successfully installed redis-2.10.5

至此pip安裝完成!

如果安裝pip時報如下錯誤:ImportError: cannot import name HTTPSHandle

執行 yum install sqlite-devel

如果報下面錯誤

python更新pip_python版本更新及pip部署方法

說明pip指令不可用,有可能是連結沒有做

[[email protected] ~]# ll /usr/bin/pip-rwxr-xr-x 1 root root 281 Jul 1 2015 /usr/bin/pip

[[email protected]~]# ln -s /usr/local/python2.7/bin/pip /usr/bin/pip

ln: creating symbolic link `/usr/bin/pip': File exists

[[email protected] ~]#

[[email protected]~]# \ln -s /usr/local/python2.7/bin/pip /usr/bin/pip

ln: creating symbolic link `/usr/bin/pip': File exists

[[email protected] ~]# mv /usr/bin/pip /tmp/##如果提示檔案存在,移走原有的檔案,重新做軟連接配接

[[email protected]~]# ln -s /usr/local/python2.7/bin/pip /usr/bin/pip

[[email protected]~]# ll /usr/bin/pip

lrwxrwxrwx1 root root 28 Dec 26 17:28 /usr/bin/pip -> /usr/local/python2.7/bin/pip

python更新pip_python版本更新及pip部署方法