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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:16:22  来源:igfitidea点击:

Macports select default Python interpreter for executing scripts?

pythonmacosmacports

提问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_selectscript changes only /opt/local/bin/python, so you have to make sure there is no other pythonbinary 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 python26in 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_selectinstead of port select --set python.

几天前它在 MacPort 2.0.0 上对我有用。如果你有一个旧的MacPorts库,那么你应该升级,或使用python_select替代port select --set python