2009-09-25 55 views
0

我在本地安裝了較新版本的Python。對於我做了以下內容:如何找到並運行我的舊(全球)版本的Python?

$ cd 
$ mkdir opt 
$ mkdir downloads 
$ cd downloads 
$ wget http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz 
$ tar xvzf Python-2.6.2.tgz 
$ cd Python-2.6.2 
$ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4 
$ make 
$ make install 

在.bash_profile中,我把下列:

export PATH=$HOME/opt/bin/:$PATH 
export PYTHONPATH=$HOME/opt/lib:$HOME/opt/lib/site-packages:$PYTHONPATH 

而且比我執行:

$ cd 
$ source .bash_profile 
$ python -V 

它的工作。我得到了一個新的Python工作版本。然而,現在我想嘗試一下我的舊版本,它是所有用戶安裝的「全局」版本。任何人都可以請求告訴我我該怎麼做?

P.S. 我厭倦了刪除.bash_profile中的更改。我已經評論了安裝新版本時添加的最後2行。所以,現在我有以下的.bash_profile文件:

# .bash_profile 

# Get the aliases and functions 
if [ -f ~/.bashrc ]; then 
     . ~/.bashrc 
fi 

# User specific environment and startup programs 

PATH=$PATH:$HOME/bin 

export PATH 

#export PATH=$HOME/opt/bin/:$PATH 
#export PYTHONPATH=$HOME/opt/lib:$HOME/opt/lib/site-packages:$PYTHONPATH 

我源文件(源.bash_profile中)的新版本。但我仍然得到舊版本的Python。當我輸入「Python -V」時,我得到「Python 2.6.2」。

+0

OK , 我懂了。我剛來這地方。但我會開始接受。 – Verrtex 2009-09-25 13:49:33

+2

請注意,您的.bashrc通過_adding_重新定義了PATH。所以,如果你的路徑已經有你的新目錄,那麼找到你的.bashrc文件將不會刪除舊路徑。要重新開始,只需啓動一個新的shell。 – 2009-09-25 14:07:14

回答

2

你可以直接調用類似「/ usr/local/bin/python myscript.py」的程序。你只需要知道你的python標準安裝位置。如果你不知道,你可以撤消更改,然後鍵入找出實際上得到當你在命令行上的「蟒蛇」,」執行「這蟒蛇」

例如:

$ /usr/bin/python -V 
Python 2.3.4 
$ /usr/bin/python2.4 -V 
Python 2.4.4 
$ /opt/local/bin/python2.7 -V 
Python 2.7a0 
$ python -V 
Python 2.5.2 
$ which python 
/usr/bin/python 

爲方便起見,你也可以創建別名:。

$ alias python2.4=/usr/bin/python2.4 
$ alias python2.5=/usr/bin/python2.5 
$ python2.4 -V 
Python 2.4.4 
$ python2.5 -V 
Python 2.5.2 

別名使它很容易讓你運行不同版本的Python放置在你的.bashrc文件,使他們始終定義

0

撤消更改到.bash_profile和執行source .bash_profile

+0

我試過了。它不起作用(我在原始問題中添加了更多細節)。 – Verrtex 2009-09-25 13:53:56