在OS X上安装python 2的最佳方法是什么? [英] What is the best way to install python 2 on OS X?

查看:170
本文介绍了在OS X上安装python 2的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一位同事希望在他的OS X(10.6)机器上使用我的python 2代码。我的代码导入了几个内置的python包,包括Tkinter和shelve,还使用了第三方包,包括numpy,scipy,matplotlib和ipython。

A colleague of mine wants to use my python 2 code on his OS X (10.6) machine. My code imports several built-in python packages, including Tkinter and shelve, and also uses third-party packages, including numpy, scipy, matplotlib, and ipython.

我'我遇到了OS X的内置python的一些问题。 (IDLE不起作用,例如*)。我怀疑我应该安装更新版本的python ,并且< a href =http://www.python.org/download/mac/tcltk/ =nofollow noreferrer>不同版本的Tk 。

I've encountered a few problems with OS X's built-in python. (IDLE doesn't work, for example*). I suspect I should install a more recent version of python, and a different version of Tk.

我的问题:


  1. 在同一台机器上有两个不同版本的python / Tk会导致问题吗?

  1. Will having two different versions of python/Tk on the same machine cause problems?

我想将终端命令'python','ipython'和'easy_install'与更新版本的python相关联。我应该怎么做?

I would like to associate the terminal commands 'python', 'ipython', and 'easy_install' with the more recent version of python. How should I do this?

当我安装像numpy这样的第三方软件包使用.dmg文件,如何控制安装的python numpy版本?

When I install third-party packages like numpy using a .dmg file, how do I control which version of python numpy installs into?

有更好的方法吗?

如果这个过程顺利,我'考虑将OS X指令添加到我的代码文档中,所以我想把这个过程归结为最简单,最通用的方法。

If this process goes well, I'd consider adding OS X instructions to my code's documentation, so I'd like to boil down this process to the simplest, most general approach.

*编辑:此外,< a href =https://stackoverflow.com/q/4765226/513688>这个

编辑:谢谢大家的有用答案。我的同事尝试了MacPorts,它似乎运行良好,但有几个speedbumps。首先,我们必须从系统安装盘安装Xcode。这不是快速或轻量级安装(几GB)。幸运的是我们还有磁盘!安装Xcode后,MacPorts易于安装。 Python和我们需要的python子包也很容易安装,但他告诉我这个安装需要几个小时。据推测,这种延迟是由于汇编造成的?他很容易将MacPorts python设置为默认值。但是,我认为我们必须手动更改'Python Launcher'应用程序,这似乎仍然默认为系统python。

Thank you everyone for the useful answers. My colleague tried MacPorts, which seems to work well, but has a few speedbumps. First we had to install Xcode from the system install disk. This is not a fast or lightweight install (several GB). Luckily we still had the disk! Once Xcode was installed, MacPorts was easy to install. Python and the python subpackages we needed were also easy to install, but he told me this installation took several hours. Presumably this delay is due to compilation? He had an easy time setting the MacPorts python as default. However, I think we have to change the 'Python Launcher' application by hand, this seems to still default to the system python.

即使他现在有一个工作系统,我很想让他尝试其他解决方案之一。我不确定我的所有代码的潜在用户是否都会容忍多小时,数千兆字节的安装。

Even though he has a working system now, I'm tempted to ask him to try one of the other solutions. I'm not sure all of my code's potential users will tolerate a multi-hour, multi-gigabyte installation.

推荐答案

使用< a href =http://www.macports.org/ =nofollow> MacPorts ,您可以同时安装python 2.6,2.7,3.1和3.2,使用自己的软件包,无需触摸内置的蟒蛇。

Using MacPorts, you can install python 2.6, 2.7, 3.1 and 3.2 at the same time, with their own packages, without ever touching the built-in python.

numpy,scipy,matplotlib和ipython也可用作大多数python版本的端口。

numpy, scipy, matplotlib, and ipython are also available as ports for most of those python versions.

此外,如果您安装 python_select 端口,您将成为能够:

Moreover, if you install the python_select port, you'll be able:


  • 选择其中哪一个(加上内置的python)是默认python;

  • to choose which one of those (plus the built-in python) is the "default" python;

通过easy_install / pip为selectedpython安装python包,如果它们不能作为端口使用。

to install python packages through easy_install/pip for the "selected" python, if they're not available as ports.

添加virtualenv,你将拥有一个非常非常灵活的Python开发环境。

Add virtualenv to the mix, and you'll have a very, very flexible Python development environment.

关于你的问题:

Q1:使用MacPorts,没有。虽然不是常用的用户,但我已经在2.6和2.7中安装并使用了matplotlib,使用python_select在两者之间切换。

Q1: with MacPorts, no. while not a frequent user, I've installed and used matplotlib in 2.6 and 2.7, switching between the two using python_select.

Q2:easy_install,pip,ipython将与他们安装的python链接。 (但请参阅提示1)

Q2: easy_install, pip, ipython will be "linked" to the python they were installed by. (but see tip 1)

问题3:安装py {26,27,xx} -numpy端口之一或 pip更容易在你的python_select'ed python下安装numpy

Q3: it's easier to install one of the py{26,27,xx}-numpy ports, or pip install numpy under your python_select'ed python.

Q4:嗯,MacPorts是我在Debian / Ubuntu APT之后知道的最好的东西.. 。: - )

Q4: well, MacPorts is the best thing I know after APT on Debian/Ubuntu... :-)

现在,如果您尝试使用MacPorts,有两个提示:

Now, two tips if you try MacPorts:


  1. MacPorts在OS X安装中与/ opt / local目录中分别安装端口,每个python版本都安装在 /opt/local/Library/Frameworks/Python.framework/Versions中/{2.5,2.6,2.7,...} 目录。使用python_select干净地使用链接切换python命令。但是...... 版本/ {2.5,2.6,2.7,...} / bin 目录(其中安装了python脚本)未添加到PATH中。只需添加: export PATH = / opt / local / Library / Frameworks / Python.framework / Versions / Current / bin:$ PATH 到你的〜/ .profile 将始终让您直接访问为所选python安装的脚本。

  1. MacPorts cleanly installs ports separately from the OS X installation, in an /opt/local directory, and each python version is installed in a /opt/local/Library/Frameworks/Python.framework/Versions/{2.5,2.6,2.7,...} directory. Using python_select cleanly switch the "python" command using links. BUT... the Versions/{2.5,2.6,2.7,...}/bin directory, where python scripts are installed, is not added to the PATH. Just adding: export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH to your ~/.profile will always give you direct access to the scripts installed for the selected python.

以避免重大意外,我已经添加了 echo选择的python是\$(python_select -s)\行到我的〜/ .profile ,所以我总是知道在打开会话时哪个是我当前选择的python ...: - )

to avoid bad surprises, I've added a echo Selected python is \"$(python_select -s)\" line to my ~/.profile, so I always know which is my currently selected python when opening a session... :-)

问候,

Georges

这篇关于在OS X上安装python 2的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆