如何:Macports 选择 python

发布于 2024-12-17 03:03:22 字数 571 浏览 11 评论 0原文

当我输入:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不必了 2024-12-24 03:03:22

用于

osx$ port select --list python

列出可用的 Python 安装。

然后使用“端口选择”的“--set”选项来设置您要使用的端口。

osx$ sudo port select --set python python27

Use

osx$ port select --list python

to list your available Python installations.

Then use the "--set" option to "port select" to set the port you wish to use.

osx$ sudo port select --set python python27
话少心凉 2024-12-24 03:03:22

为什么会发生这种情况

MacPorts 默认将二进制文件安装到 /opt/local默认情况下

Mac 上还有预装 python。当只需输入 python 启动时,它将启动不受 MacPorts 安装影响的预装 python 版本。

要查看仅键入 python 时将执行的版本,请使用

which python

要启动 mac ports 版本,请使用

/opt/local/bin/python2.5

解决方案

如果您希望始终使用 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

which python

To start the mac ports version use

/opt/local/bin/python2.5

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 example sudo port select --set python python27 to select 2.7. For more information type port help select.

ゝ杯具 2024-12-24 03:03:22

您的 shell 可能会缓存 python 的调用,并且不会再次在 PATH 中查找。因此,当您在同一 shell 会话中的 port select 之前调用 python 时,您需要清除此缓存。

对于 bash,请使用清除缓存

hash -r

或简单地打开一个新的终端窗口。

Your shell probably caches the invocation of python and does not look in PATH again. So, when you called python before port select in the same shell session, you need to clear this cache.

For bash, clear the cache using

hash -r

or simply open a new terminal window.

心头的小情儿 2024-12-24 03:03:22

Python 安装到:

  • 默认 (Apple):/usr/local/bin
  • MacPorts:/opt/local/bin
  • python.org:/Library/Frameworks/python...

系统需要默认的python,所以最好不要过多地弄乱它。 MacPorts Python 使用起来很方便,因为获取包非常容易。

您可以将链接设置为快捷方式:

sudo ln -s /opt/local/bin/python /usr/local/bin/ppython

然后从命令行使用MacPorts版本:

ppython script.py

Python installs to:

  • Default (Apple): /usr/local/bin
  • MacPorts: /opt/local/bin
  • python.org: /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:

sudo ln -s /opt/local/bin/python /usr/local/bin/ppython

Then from command-line to use MacPorts version:

ppython script.py
怪我入戏太深 2024-12-24 03:03:22

另一种方法是对每个 Jupyter 二进制文件进行符号链接,这样版本号就不会出现:

cd /opt/local/bin
JUPYTER_VERSION=2.7
for a in jupyter*$JUPYTER_VERSION; do sudo ln -s $a $(echo $a | sed -e 's:-'$JUPYTER_VERSION':g'); done

An alternative is symlinking each and every Jupyter binary so that the version number does not appear:

cd /opt/local/bin
JUPYTER_VERSION=2.7
for a in jupyter*$JUPYTER_VERSION; do sudo ln -s $a $(echo $a | sed -e 's:-'$JUPYTER_VERSION':g'); done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文