有時我們需要檢視python的安裝位置,好安裝第三方庫,linux可以先python進入python cmd,然後輸入
import sys
print sys.path
即可列印所有python路徑。
wget
解壓檔案
[aa@localhost ~]$ tar jxvf python-2.7.4.tar.bz2
[niuxl@localhost ~]$ cd python-2.7.4
[niuxl@localhost python-2.7.4]$ ls
config.guess configure demo grammar install-sh license makefile.pre.in modules parser pcbuild python riscos tools
config.sub configure.ac doc include lib mac misc objects pc pyconfig.h.in readme setup.py
[niuxl@localhost python-2.7.4]$ su -
口令:[root@localhost ~]# mkdir /usr/local/python2.7.4
[root@localhost ~]# cd /home/
[root@localhost home]# cd niuxl/python-2.7.4
[root@localhost python-2.7.4]# ls
config.guess configure demo grammar install-sh license makefile.pre.in modules parser pcbuild python riscos tools
config.sub configure.ac doc include lib mac misc objects pc pyconfig.h.in readme setup.py
編譯之前,需要先安裝zlib包:
[root@localhost python-2.7.4]# yum install zlib zlib-devel
[root@localhost python-2.7.4]# ./configure --prefix=/usr/local/python2.7.4
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking machdep... linux2
checking extraplatdir...
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/home/niuxl/python-2.7.4':
configure: error: no acceptable c compiler found in $path
缺少c編輯器
[root@localhost python-2.7.4]# yum install gcc
..略gcc安裝完成
繼續編譯python
[root@localhost python-2.7.4]# ./configure --prefix=/usr/local/python2.7.4
..(略)
ok編譯成功
[root@localhost python-2.7.4]# make && make install
安裝成功
[root@localhost python-2.7.4]# python -v
python 2.4.3
目前版本依然是2.4.3,現在開始公升級python,
檢視python命令所在目錄
[root@localhost python-2.7.4]# whereis python
python: /usr/bin/python2.4 /usr/bin/python /usr/lib/python2.4 /usr/include/python2.4 /usr/share/man/man1/python.1.gz
將/usr/bin/python 的軟連線修改為python2.4.3
[root@localhost python-2.7.4]# mv /usr/bin/python /usr/bin/python2.4.3
[root@localhost python-2.7.4]# python
-bash: /usr/bin/python: 沒有那個檔案或目錄
python命令找不到,這時只需要將版本python2.7.4命令加入環境變數即可!
方式1:
修改/etc/profile加入如下兩行:
path=$path:/usr/local/python2.7.4/bin
export path
然後[root@localhost python-2.7.4]# source /etc/profile
[root@localhost python-2.7.4]# python -v
python 2.7.4
當然也可以建立2.7.4版本的python的軟連線:/usr/bin/python
[root@localhost ~]# ln -s /usr/local/python2.7.4/bin/python /usr/bin/python
亦可ok,python公升級完成
到現在為止,還有最後一件事需要做,那就是yum與python的相容問題:
[root@localhost pipe]# vi /usr/bin/yum
#!/usr/bin/python
第一行修改為
#!/usr/bin/python2.4.3(即原始的python變更後的名字)(ps:我自己這問題還是沒有解決。即使修改了之後。 依舊會有報錯。)
將linux預設python公升級到2 7 4版本
wget 解壓檔案 aa localhost tar jxvf python 2.7.4.tar.bz2 niuxl localhost cd python 2.7.4 niuxl localhost python 2.7.4 ls config.guess configure demo gramm...
將linux預設python公升級到2 7 4版本
wget 解壓檔案 aa localhost tar jxvf python 2.7.4.tar.bz2 niuxl localhost cd python 2.7.4 niuxl localhost python 2.7.4 ls config.guess configure demo gramm...
centos7將python預設版本公升級
centos7將python預設版本公升級 想用centos7來寫python,但是預設安裝的是python2.7 python v命令可以檢視版本資訊 準備公升級到python3.5.2 首先安裝編譯環境 yum y install gcc wget 然後解壓建立安裝編譯備份 解壓 tar zxv...