通过 mac 端口运行 python

通过 mac 端口运行 python

我已经通过 mac 端口安装了 python,使用:

sudo port install python33

然后我做了:

sudo port select --set python python33

并得到:

Selecting 'python33' for 'python' succeeded. 'python33' is now active.

然而当我这样做时which python我得到:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

which python3得到:

/Library/Frameworks/Python.framework/Versions/3.1/bin/python3

我做错了什么?

当我做:port select --list python

我得到:

Available versions for python:
    none
    python25-apple
    python33 (active)

当我这样做时type -a python,我得到:

python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
python is /opt/local/bin/python
python is /usr/bin/python
python is /usr/local/bin/python

当我输入:echo $PATH 时,我得到:

/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.1/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/X11R6/bin

答案1

它会在路径上查找它能找到的第一个 python。port select 会更改 /opt/local/bin/python 以调用所选的 python。要使它正常工作,/opt/local/bin 必须位于路径上任何其他包含 python 的目录之前。

就您而言,您之前/Library/Frameworks/Python.framework/Versions/2.7/bin有。/Library/Frameworks/Python.framework/Versions/3.1/bin/opt/local/bin

您需要清理路径。我建议从头开始,只添加您知道和理解的目录。您似乎已经以多种方式安装了 python,并且还安装了 fink 和 macports。我只会使用其中一个包管理器并从路径中删除所有显式 python。

相关内容