準備環(huán)境安裝包:
python3.6:[下載地址]
distribute: [下載地址]
setuptools:[下載地址]
pip: [下載地址]
安裝編譯器:
yum install gcc gcc-c++ -y
安裝依賴包:
yum install openssl-devel -y #安裝ansible會用到
yum install zlib zlib-devel -y #安裝setuptools會用到
yum install sqlite-devel #安裝django會用到
安裝Python3.6.2:
[root@localhost app]# xz -d Python-3.6.2.tar.xz
[root@localhost ~]# tar -xvf Python-3.6.2.tar
[root@localhost ~]# cd Python-3.6.2
[root@localhost Python-3.6.2]# ./configure
[root@localhost Python-3.6.2]# make
[root@localhost Python-3.6.2]# make install
非常重要:
代替make install的命令傍衡,使用make altinstall (altinstall功能說明)
個人總結說明:
使用make install型雳,會覆蓋系統(tǒng)默認安裝的Python2.6版本砰左。即用make install命令執(zhí)行完,輸入python猪狈,出現(xiàn)下圖:
原來的Python2.6不在了,是不是很神奇界阁。如果想要原來的Python2.6存在令漂,則需要使用altinstall。
使用make altinstall安裝组贺,輸入python凸舵,出現(xiàn)下圖:
python重要目錄結構說明:
在/usr/bin目錄下(這是系統(tǒng)默認Python): [root@localhost bin]# ls -trl py* -rwxr-xr-x. 1 root root 188 8月 21 2010 pygtk-demo -rwxr-xr-x. 1 root root 78 7月 24 2015 pydoc -rwxr-xr-x. 2 root root 4864 7月 24 2015 python2.6 -rwxr-xr-x. 2 root root 4864 7月 24 2015 python lrwxrwxrwx. 1 root root 6 7月 19 17:47 python2 -> python
在/usr/local/bin目錄下(這是Python源碼安裝的默認安裝路徑): -rwxr-xr-x. 1 root root 101 7月 21 18:46 2to3-3.6 -rwxr-xr-x. 1 root root 242 7月 21 18:46 easy_install-3.6 -rwxr-xr-x. 1 root root 99 7月 21 18:46 idle3.6 -rwxr-xr-x. 1 root root 214 7月 21 18:46 pip3.6 -rwxr-xr-x. 1 root root 84 7月 21 18:46 pydoc3.6 -rwxr-xr-x. 2 root root 9971089 7月 21 18:44 python3.6 -rwxr-xr-x. 2 root root 9971089 7月 21 18:44 python3.6m -rwxr-xr-x. 1 root root 3083 7月 21 18:46 python3.6m-config -rwxr-xr-x. 1 root root 441 7月 21 18:46 pyvenv-3.6 在/usr/local/lib目錄下(這是Python源碼安裝的默認庫文件目錄): drwxr-xr-x. 28 root root 20480 7月 21 18:41 python3.6
添加文件鏈接(實現(xiàn)輸入python,是3.6.2版本):
cd /usr/local/bin
cp python3.6 /usr/bin/
cd /usr/bin
rm python
rm python2
cd /usr/bin
ln -s python2.6 python2
ln -s python3.6 python3
cp python3.6 python
安裝完后失尖,使用yum出現(xiàn)的問題:
升級完python到3.6之后啊奄,會出現(xiàn)這樣的問題:使用make install則不出現(xiàn),而用make altinstall則會出現(xiàn)掀潮。
解決辦法:
cd /usr/bin
vi yum
把第一行#!/usr/bin/python改成#!/usr/bin/python2.6
后來發(fā)現(xiàn)pip已經(jīng)默認繼承在安裝包里了(/usr/local/bin)菇夸,下面的可以不做。
pip is already installed if you are using Python 2 >=2.7.9 or Python 3 >=3.4 downloaded from python.org
安裝包管理工具:
說明:在python3里安裝包管理工具仪吧,安裝pip前庄新,先安裝distribute,如果安裝setuptools薯鼠,則會報錯择诈。(如果有人知道為什么凡蚜,請告訴我下,謝謝?源印3!)
1.安裝 distribute:
[root@localhost ~]# unzip distribute-0.7.3.zip
[root@localhost ~]# cd distribute-0.7.3
[root@localhost distribute-0.7.3]# python2 setup.py install
#用easy_install命令測試是否完成安裝
[root@localhost distribute-0.7.3]# easy_install
error: No urls, filenames, or requirements specified (see --help)
2.安裝pip:
方式一:
[root@localhost ~]# easy_install pip
方式二:
[root@localhost ~]# tar -xvf pip-9.0.1.tar.gz
[root@localhost ~]# cd pip-9.0.1
[root@localhost pip-9.0.1]# python setup.py install
為什么升級到2.7用setuptools涩金,而升級到3.6用distribute:
http://blog.csdn.net/ichuzhen/article/details/24640299