如何找到并运行我旧的(全局)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版本可以使用。不过,现在我想试试我之前的那个版本,它是一个“全局”的版本,是由系统管理员为所有用户安装的。有没有人能告诉我该怎么做呢?
附注: 我尝试去掉在.bash_profile里做的更改。我把安装新版本时添加的最后两行注释掉了。所以,现在我的.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
然后我更新了这个文件(用source .bash_profile命令)。但是我还是得到了旧版本的Python。当我输入“Python -V”时,显示的是“Python 2.6.2”。
2 个回答
0
撤销你对 .bash_profile
文件的修改,然后执行 source .bash_profile
这个命令。
2
你可以直接用类似 "/usr/local/bin/python myscript.py" 的方式来运行程序。你只需要知道你安装的python在哪里。如果不知道,可以撤销你之前的改动,然后输入 "which python" 来查找当你在命令行输入 "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 文件里,这样它们就会一直有效。