linux設定python環境變數
(2012-02-08 14:41:24)
轉載▼
添加環境變數主要是在/etc/profile中
例如,在/usr/local/下安裝了python2.7
因為系統預設是2.4,所以
#python
Python 2.4.3 (#1, Sep
3 2009, 15:37:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
進入python2.7的安裝路徑,在/bin下找到python檔案
./python
Python 2.7.2 (default, Feb 2 2012, 11:45:14)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
先查看下目前的環境變數
#echo $PATH
/usr/local/jdk1.5/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
預設是沒有最新的python2.7的
我進入新裝的python2.7目錄查看
/usr/local/python/bin/python2.7
這個就是python2.7的開機檔案
# PATH=$PATH:/usr/local/python/bin/
# echo $PATH
/usr/local/jdk1.5/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/python/bin/
將新裝的/usr/local/python/bin添加到環境變數中
這時當我們輸入
# python2.7
Python 2.7.2 (default, Feb 2 2012, 11:45:14)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
因為系統會自動在環境中找尋python2.7這個檔案並啟動,但會優先找/usr/bin下的開機檔案,所以
當#python時,還是會進入2.4的預設系統
進入/usr/bin,將python刪除,建立串連
ln -s /usr/local/python/bin/python ./python
這樣我們#python 的時候,就會直接進入2.7的環境了