我怀疑在Mac OS X 10.6.3上安装了多个Python 2.6版本;如何设置Terminal启动哪个?
当我在终端输入 python
时,它会加载 Python 2.6.2。不过,我的电脑上有好几个地方都有叫做 Python 2.6 的文件夹。我不太确定这是因为 Python 2.6 被安装在了不同的地方,还是说 Python 就喜欢在不同的地方放很多文件夹。
如果真的有多个安装版本的话,我希望能设置一下,指定用哪个版本。
3 个回答
1
来自OS X Python手册页(man python):
CHANGING THE DEFAULT PYTHON
Using
% defaults write com.apple.versioner.python Version 2.5
will make version 2.5 the user default when running the both the python
and pythonw commands (versioner is the internal name of the version-
selection software used).
To set a system-wide default, replace `com.apple.versioner.python' with
`/Library/Preferences/com.apple.versioner.python' (admin privileges will
be required).
The environment variable VERSIONER_PYTHON_VERSION can also be used to
set the python and pythonw version:
% export VERSIONER_PYTHON_VERSION=2.5 # Bourne-like shells
or
% setenv VERSIONER_PYTHON_VERSION 2.5 # C-like shells
% python ...
This environment variable takes precedence over the preference file
settings.
1
别把事情搞复杂。在你的 ~/.bash_aliases
文件里放入以下内容(假设你在用 bash):
alias py26="/usr/bin/python-2.6.1"
alias py30="/usr/bin/python-3.0.0"
当然,我刚才写的那些路径是我随便编的。你要根据自己系统的实际情况来填写。如果 ~/.bash_aliases
文件不存在,就自己新建一个。
使用的时候,只需要在命令行输入 py26
,就会启动相应的解释器。
4
当你在命令行或者终端里输入 python
时,它会执行在你的 PATH
环境变量中找到的第一个可执行文件。
如果你想知道到底执行的是哪个文件,可以使用 which python
或者 where python
命令。