macos Macports 选择默认的 Python 解释器来执行脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6943812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Macports select default Python interpreter for executing scripts?
提问by goh
I used python_select
, it seems like it does not change the default python for executing scripts, for instance django-admin.py runserver
(without python in front).
我使用过python_select
,它似乎不会更改执行脚本的默认 python,例如django-admin.py runserver
(前面没有 python)。
How do i change this?
我如何改变这个?
回答by fviktor
There is /usr/bin/python
, which is usually earlier in the path (has a higher precedence) than MacPort's binary folder (/opt/local/bin/python
). The python_select
script changes only /opt/local/bin/python
, so you have to make sure there is no other python
binary on your path taking precedence over it.
有/usr/bin/python
,通常在路径中比 MacPort 的二进制文件夹 ( /opt/local/bin/python
)更早(具有更高的优先级)。该python_select
脚本只改变/opt/local/bin/python
肯定是没有的,所以你必须让python
你的路径优先于它的二进制文件。
Solution (as root):
解决方案(以 root 身份):
mv /usr/bin/python /usr/bin/python.orig
ln -s /opt/local/bin/python /usr/bin/python
port select --set python python26
Make sure you replace python26
in the third line with your intended Python version.
确保python26
将第三行中的内容替换为您想要的 Python 版本。
It worked for me a few days ago with MacPort 2.0.0. If you have an older MacPorts library, then you should either upgrade it or use python_select
instead of port select --set python
.
几天前它在 MacPort 2.0.0 上对我有用。如果你有一个旧的MacPorts库,那么你应该升级,或使用python_select
替代port select --set python
。