![在 Snow Leopard 上更改 python 符号链接?](https://linux22.com/image/557002/%E5%9C%A8%20Snow%20Leopard%20%E4%B8%8A%E6%9B%B4%E6%94%B9%20python%20%E7%AC%A6%E5%8F%B7%E9%93%BE%E6%8E%A5%EF%BC%9F.png)
我的 Snow Leopard 上安装了两个 python 2.5.4,不要问为什么。
当我从命令行运行“python”时,构建 5363 就会启动。当我运行/usr/bin/python2.5
构建 5646(我需要的那个)时,就会启动。在您询问之前,构建号并不是它们之间的唯一区别,也是构建的“类型”,所以我真的无法开始使用这个 5363。
问题是,我需要的应用程序崩溃了(wxPython 中出现异常,无法在 Google 上搜索到该异常),而且我怀疑当我使用正确的 python 构建启动主应用程序时,线程会以错误的线程启动(之前在另一个系统上使用同一个应用程序时也发生过这种情况)。
我该如何更改“默认”python 2.5 以开始正确的构建?
我的路径是:
/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
which python
仅返回:
/Library/Frameworks/Python.framework/Versions/Current/bin/python
ls -la /usr/bin/python*
返回:
-rwxr-xr-x 2 root wheel 86000 Sep 25 2010 /usr/bin/python
-rwxr-xr-x 5 root wheel 925 Sep 25 2010 /usr/bin/python-config
lrwxr-xr-x 1 root wheel 75 Sep 25 2010 /usr/bin/python2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
lrwxr-xr-x 1 root wheel 82 Sep 25 2010 /usr/bin/python2.5-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
lrwxr-xr-x 1 root wheel 75 Sep 25 2010 /usr/bin/python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x 1 root wheel 82 Sep 25 2010 /usr/bin/python2.6-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
-rwxr-xr-x 2 root wheel 86000 Sep 25 2010 /usr/bin/pythonw
lrwxr-xr-x 1 root wheel 76 Sep 25 2010 /usr/bin/pythonw2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5
lrwxr-xr-x 1 root wheel 76 Sep 25 2010 /usr/bin/pythonw2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6
ls -la /usr/local/bin/python*
返回:
lrwxr-xr-x 1 root wheel 68 Apr 22 2010 /usr/local/bin/python -> ../../../Library/Frameworks/Python.framework/Versions/2.5/bin/python
lrwxr-xr-x 1 root wheel 75 Apr 22 2010 /usr/local/bin/python-config -> ../../../Library/Frameworks/Python.framework/Versions/2.5/bin/python-config
lrwxr-xr-x 1 root wheel 71 Apr 22 2010 /usr/local/bin/python2.5 -> ../../../Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
lrwxr-xr-x 1 root wheel 78 Apr 22 2010 /usr/local/bin/python2.5-config -> ../../../Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
lrwxr-xr-x 1 root wheel 69 Apr 22 2010 /usr/local/bin/pythonw -> ../../../Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw
lrwxr-xr-x 1 root wheel 72 Apr 22 2010 /usr/local/bin/pythonw2.5 -> ../../../Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5
我既不是 Python 专家也不是 *nix 专家,再加上 Mac,我感觉就很无助了……
请帮忙!
答案1
在 Mac OS X 上安装同一版本的多个 Python 实例并不罕见。
看起来你可能从 python.org 安装了一个 python2.5(即 中的符号链接/usr/local/bin
),但现在你只想使用 Apple 提供的系统 Python 2.5(在 中/usr/bin
)。导致前者首先被找到的原因是你的 shell 执行路径。实际上/usr/local/bin/python
指向 中的一个文件
/Library/Frameworks/Python.framework/Versions/Current/bin/
这是 python.org 安装的一部分。默认情况下,python.org 安装程序会修改您的 shell 启动文件以将此目录插入到路径的开头。要撤消此操作,您可以恢复旧的启动文件。如果您使用的是默认 bash shell,则启动文件已命名,.bash_profile
并且 Python 安装程序可能将原始启动文件的副本保存为.bash_profile.pysave
。从终端会话中,您可以检查并恢复原始文件,如下所示:
$ cd $HOME
$ ls .*.pysave
.bash_profile.pysave .profile.pysave
#
# compare the current file to the original saved file
#
# You'll probably see something like the following:
#
$ diff .bash_profile .bash_profile.pysave
4c4
---> # Setting PATH for MacPython 2.5
13c13
< PATH="/Library/Frameworks/Python.framework/Versions/2.5/bin:${PATH}"
---
#
# If so, it is safe to copy the saved file back and not lose
# any other changes you might have made
#
$ cp -p .bash_profile.pysave .bash_profile
#
# Then you will need to start a new Terminal session to see the changed PATH
如果您愿意或者.pysave
找不到该文件,您可以手动编辑该文件以删除多余的目录。
答案2
省去头痛,使用Pythonbrew管理不同的 Python 版本。无需处理符号链接等。安装和使用非常简单。