更新python千萬不要把老版本的刪除!新老版本是能夠共存的,不少基本的命令、
軟件包都要依賴預裝的老版本python的,好比yum。python
1. 查看 python 版本
[jack@ ~]$ python -V
Python 2.7.5sql
2.編譯前準備
python 在編譯以前配置的時候會探測環境的庫是否存在,有的庫不在,對應的功能會放棄bootstrap
爲了安裝setuptools,要須要安裝zlib:python2.7
yum install zlib zlib-dev
爲在python編譯時加入ssl模塊,yum安裝openssl和openssl-devel:ide
yum install openssl測試
yum install openssl-develui
209 sudo yum install openssl
210 sudo yum install openssl-devel
211 sudo yum install ncurses-libs
212 sudo yum install readline-devel
213 sudo yum install sqlite-devel
214 sudo yum install bzip2-devel
215 sudo yum install gdbm-devel
216 sudo yum install libdbi-develthis
2.編譯python 2.7.13
cd /home/jack/work/
wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
tar xvf Python-2.7.13.tgz
cd Python-2.7.13
./configure --prefix=/usr/local/python27
sudo make
sudo make install
3 . 本來的鏈接url
4. 修改鏈接
sudo mv /usr/bin/python2 /usr/bin/python2_old
sudo mv /usr/bin/python2.7 /usr/bin/python2.7.5
sudo mv /usr/bin/python /usr/bin/python_oldsqlite
sudo ln -s /usr/local/python27/bin/python2.7 /usr/bin/python2
sudo ln -s /usr/bin/python2 /usr/bin/python
其中用到了 python2 的目的是 ,之後有可能會用到python3
/usr/bin/python2 和 /usr/bin/python2.7 應該須要刪掉
由於有的python 腳本里面會註明使用 /usr/bin/python2
5. 解決 yum的問題
yum 須要用到原來的 python2.7.5
sudo vi /usr/bin/yum
sudo vi /usr/libexec/urlgrabber-ext-down
6 測試一下 yum 是否可以正常使用
yum info gcc
查找和顯示
yum info package1 顯示安裝包信息package1
yum list 顯示全部已經安裝和能夠安裝的程序包
yum list package1 顯示指定程序包安裝狀況package1
yum groupinfo group1 顯示程序組group1信息yum search string 根據關鍵字string查找安裝包
7 安裝python2.7.13 對應的pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
The script wheel is installed in ‘/usr/local/python27/bin’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use –no-warn-script-location.
8 替換原來的pip
原來的pip
sudo mv /usr/bin/pip /usr/bin/pip_old
sudo mv /usr/bin/pip2 /usr/bin/pip2_old
sudo mv /usr/bin/pip2.7 /usr/bin/pip2.7_old
sudo cp /usr/local/python27/bin/pip* /usr/bin/
9 測試一下 pip
10 設置環境變量
sudo vi /etc/profile
在最後面加上
export PYTHON_HOME=/usr/local/python27
export PATH=$PYTHON_HOME/bin:$PATH
source /etc/profile # 當前終端生效,reboot後纔會徹底生效
echo $PATH
遇到問題:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _curses _curses_panel
_sqlite3 _ssl _tkinter
bsddb185 bz2 dbm
dl gdbm imageop
readline sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module’s name.
running build_scripts
209 sudo yum install openssl
210 sudo yum install openssl-devel
211 sudo yum install ncurses-libs
212 sudo yum install readline-devel
213 sudo yum install sqlite-devel
214 sudo yum install bzip2-devel
215 sudo yum install gdbm-devel
216 sudo yum install libdbi-devel
遇到問題
Traceback (most recent call last):
File 「get-pip.py」, line 20649, in
main()
File 「get-pip.py」, line 197, in main
bootstrap(tmpdir=tmpdir)
File 「get-pip.py」, line 82, in bootstrap
import pip._internal
zipimport.ZipImportError: can’t decompress data; zlib not available
yum install zlib zlib-devel -y yum -y install zlib*