如何:Macports 选择 python
当我输入:
port select --list python
这是结果:
Available versions for python:
none
python25 (active)
python25-apple
python26-apple
python27
python27-apple
我想当我使用 python 时我会使用版本 2.5
。相反,当我输入“python”时,版本 2.7 似乎处于活动状态。如何将其更改为 2.5 版本?
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
When I enter:
port select --list python
This is the result:
Available versions for python:
none
python25 (active)
python25-apple
python26-apple
python27
python27-apple
I thought when I use python I would be using version 2.5
. Instead when I enter "python", version 2.7 seems to be active. How do I change that to version 2.5?
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(5)
用于
列出可用的 Python 安装。
然后使用“端口选择”的“--set”选项来设置您要使用的端口。
Use
to list your available Python installations.
Then use the "--set" option to "port select" to set the port you wish to use.
为什么会发生这种情况
MacPorts 默认将二进制文件安装到
/opt/local
中默认情况下。Mac 上还有预装 python。当只需输入
python
启动时,它将启动不受 MacPorts 安装影响的预装 python 版本。要查看仅键入 python 时将执行的版本,请使用
要启动 mac ports 版本,请使用
解决方案
如果您希望始终使用 MacPorts 二进制文件,您可以更改路径,以便出现
/opt/local/bin
< em>before/use/local/bin
等。/opt/local/bin
等由 MacPorts 添加到 ~/.tcshrc 中。另外,请务必查看 ~/.profile 和 ~/.bash_profile,因为它们是 mac 上的默认值。在 ports 中选择版本
首先输入
port select --list python
列出已安装的版本,然后例如sudo port select --set python python27
选择 2.7。有关更多信息,请输入port help select
。Why this happens
MacPorts installs binaries into
/opt/local
by default.There is also a preinstalled python on your Mac. When just typing
python
to start, it will start the preinstalled python version not affected by MacPorts install.To see what version will be executed when just typing python use
To start the mac ports version use
Solution
If you wish to always use MacPorts binaries you can change your path so that
/opt/local/bin
appears before/use/local/bin
etc./opt/local/bin
etc. are added in ~/.tcshrc by MacPorts. Also be sure to look in ~/.profile and ~/.bash_profile as these are default on mac.Selecting version in ports
First type
port select --list python
to list installed version, then just for examplesudo port select --set python python27
to select 2.7. For more information typeport help select
.您的 shell 可能会缓存
python
的调用,并且不会再次在 PATH 中查找。因此,当您在同一 shell 会话中的port select
之前调用python
时,您需要清除此缓存。对于 bash,请使用清除缓存
或简单地打开一个新的终端窗口。
Your shell probably caches the invocation of
python
and does not look in PATH again. So, when you calledpython
beforeport select
in the same shell session, you need to clear this cache.For bash, clear the cache using
or simply open a new terminal window.
Python 安装到:
/usr/local/bin
/opt/local/bin
/Library/Frameworks/python
...系统需要默认的python,所以最好不要过多地弄乱它。 MacPorts Python 使用起来很方便,因为获取包非常容易。
您可以将链接设置为快捷方式:
然后从命令行使用MacPorts版本:
Python installs to:
/usr/local/bin
/opt/local/bin
/Library/Frameworks/python
...Default python is required by system so best not to mess with it too much. MacPorts Python convenient to use because getting packages so easy.
You can set link as shortcut:
Then from command-line to use MacPorts version:
另一种方法是对每个 Jupyter 二进制文件进行符号链接,这样版本号就不会出现:
An alternative is symlinking each and every Jupyter binary so that the version number does not appear: