切换 python 发行版

发布于 2024-09-08 02:03:05 字数 256 浏览 8 评论 0原文

我有一台配备 Snow Leopard 的 MacBook Pro,以及标配的 Python 2.6 发行版。 Numpy 无法正常工作。 Loadtxt 给出文件名太长的错误,而 getfromtxt 根本不起作用(模块中没有对象错误)。然后我尝试在 MacPorts 上下载 py26-numpy 端口。当然,当我使用python时,它默认是mac发行版。我如何将其切换为使用 MacPorts 的最新、最好的版本。这看起来比从源代码构建我需要的所有工具要简单得多...

谢谢!

I have a MacBook Pro with Snow Leopard, and the Python 2.6 distribution that comes standard. Numpy does not work properly on it. Loadtxt gives errors of the filename being too long, and getfromtxt does not work at all (no object in module error). So then I tried downloading the py26-numpy port on MacPorts. Of course when I use python, it defaults the mac distribution. How can I switch it to use the latest and greatest from MacPorts. This seems so much simpler than building all the tools I need from source...

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

少钕鈤記 2024-09-15 02:03:05

首先,将 MacPorts 路径 (/opt/local/bin) 添加到 $PATH 中。在 .bashrc (或您使用的任何 shell 配置文件)中:

export PATH="/opt/local/bin:${PATH}"

如果您通过 MacPorts 安装了多个版本的 Python,和/或想要在 MacPorts 和 Apple 发行版之间轻松切换,您可以安装 < a href="http://trac.macports.org/browser/trunk/dports/sysutils/python_select/Portfile" rel="nofollow noreferrer">python_select 端口。

另请注意,MacPorts 版本的 Python 2.6 安装在 /opt/local/bin/python2.6 中,因此要使用该解释器,您必须执行以下三件事之一:

  1. 启动解释器使用python2.6(不仅仅是python)。
  2. 设置 shell 别名,以便 python 调用 python2.6alias python=python2.6)。
  3. /opt/local/bin/python 手动设置符号链接 -> /opt/local/bin/python2.6
  4. 使用python_select设置调用python使用的Python。

选项#3 或#4 可能是最好的选择。

First of all, add the MacPorts path (/opt/local/bin) to your $PATH. In .bashrc (or whatever shell config file you use):

export PATH="/opt/local/bin:${PATH}"

If you have multiple versions of Python installed via MacPorts, and/or want to easily switch between the MacPorts and Apple distributions, you can install the python_select port as well.

Also note that the MacPorts version of Python 2.6 is installed into /opt/local/bin/python2.6, so to use that interpreter, you'll have to do one of three things:

  1. Start the interpreter using python2.6 (not just python).
  2. Set up a shell alias so that python calls python2.6 (alias python=python2.6).
  3. Manually set up a symlink from /opt/local/bin/python -> /opt/local/bin/python2.6.
  4. Use python_select to set the Python used by calling python.

Options #3 or #4 are probably the best bet.

人生百味 2024-09-15 02:03:05

您需要更新您的PATH,以便MacPorts中的内容位于标准系统目录的前面,例如export PATH=/opt/local/bin:/opt/local/sbin: /opt/local/Library/Frameworks/Python.framework/Versions/Current/bin/:$PATH

更新:要特别注意 /opt/local/Library/Frameworks/Python.framework/Versions/Current/bin 在旧 前面路径值。

You need to update your PATH so that the stuff from MacPorts is in front of the standard system directories, e.g., export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin/:$PATH.

UPDATE: Pay special attention to the fact that /opt/local/Library/Frameworks/Python.framework/Versions/Current/bin is in front of your old PATH value.

烦人精 2024-09-15 02:03:05

现有的答案非常有用,但我注意到它们都没有说明如何使更改坚持下去。如果您不熟悉 unix 命令行,这可能很重要。

首先,解释一下:在基于 UNIX 的操作系统中,shell 中的重要配置信息存储在称为环境变量的东西中。名为 PATH 的环境变量将您的 shell 定向到查找程序的位置列表。当您键入命令时,它从 PATH 变量的最左端开始,并在该文件夹中查找您尝试运行的程序。如果找到,则运行它;否则它会在下一个文件夹中查找。当安装了同一程序的多个版本时,可以使用 PATH 变量给予一个优先级。

要使用此功能,请将包含闪亮新版本的文件夹放在路径前面,如下所示:

PATH=/opt/local/bin:/usr/bin:/usr/local/bin

要在 shell 的单个版本中进行此更改,您可以键入

export PATH=/opt/local/bin:/usr/bin:/usr/local/bin

要在打开的每个 shell 中进行更改,您需要指示您的 shell 在每次启动时设置此变量。有一个名为 .bashrc 的文件,另一个名为 .bash_profile 的文件,bash 在启动时会读取该文件。 .bashrc 文件通常用于包含所有 shell 的指令,而 .bash_profile 用于仅包含交互式 shell 的指令。因此,要使此更改生效,您可以编辑 /Users/yourname/.bashrc 以包含如下行:

export PATH="/opt/local/bin:$PATH"

其作用是添加 /opt/local/bin到路径变量的前面,同时保留路径的其余部分。如果该更改似乎不起作用,您需要通过将 source $HOME/.bashrc 添加到 .bash_profile 脚本来确保调用 .bashrc,或者只需将必要的行移至 .bash_profile 中即可。

The existing answers are quite useful, but I noticed that neither of them spell out how to make the change stick. If you're not familiar with the unix command line this might be important.

First, and explanation: In unix based operating systems, important configuration information in the shell is stored in things called environment variables. The environment variable called PATH directs your shell to a list of places to look for programs. When you type a command, it starts at the leftmost end of the PATH variable, and looks in that folder for the program you tried to run. If it finds it, it runs it; else it looks in the next folder. When you have multiple versions of the same program installed, you can use the PATH variable to give one precedence.

To make use of this, put the folder with the shiny new version in front of the path, like this:

PATH=/opt/local/bin:/usr/bin:/usr/local/bin

To make this change in a single version of your shell, you can type

export PATH=/opt/local/bin:/usr/bin:/usr/local/bin

To make the change in every shell you open, you need to instruct your shell to set this variable every time it starts. There is a file called .bashrc, and another one called .bash_profile that bash will read when it starts up. The .bashrc file is generally used to contain instructions for all shells, and .bash_profile is used to contain instructions only for interactive shells. So, to make this change stick, you can edit /Users/yourname/.bashrc to include a line like this:

export PATH="/opt/local/bin:$PATH"

What that does is add /opt/local/bin to the front of the path variable while leaving the rest of the path alone. If that change doesn't seem to work, you will need to either ensure .bashrc is getting called by adding source $HOME/.bashrc to your .bash_profile script, or just move the necessary line into .bash_profile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文