在OS X上/usr/bin/python与/opt/local/bin/python2.7 [英] /usr/bin/python vs /opt/local/bin/python2.7 on OS X

查看:160
本文介绍了在OS X上/usr/bin/python与/opt/local/bin/python2.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否阐明OS X随附的Python解释器与可以通过MacPorts安装的Python解释器之间的交互?

Can you shed some light on the interaction between the Python interpreter distributed with OS X and the one that can be installed through MacPorts?

在安装networkxmatplotlib时,我很难与/usr/bin/python/opt/local/bin/python2.7进行交互. (后者本身是指向/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7的软指针)

While installing networkx and matplotlib I am having difficulties with the interaction of /usr/bin/python and /opt/local/bin/python2.7. (The latter is itself a soft pointer to /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7)

如何确定我一次使用的是哪个Python,pip和Python库?

How can I be certain which Python, pip, and Python libraries I am using at any one time?

更重要的是,似乎无法在Lion上安装matplotlib. Requires numpy 1.6 or later to build. (Found 1.5.1)失败.如果我通过运行sudo pip install --upgrade numpy进行升级,则无济于事.随后尝试安装matplotlib(sudo /usr/local/bin/pip install matplotlib)仍然失败,并显示相同的(Requires numpy 1.6...)消息.如何安装matplotlib?

More importantly, it appears that installing matplotlib is not possible on Lion. It fails with Requires numpy 1.6 or later to build. (Found 1.5.1). If I upgrade by running sudo pip install --upgrade numpy, it does not help. Subsequently attempting to install matplotlib (sudo /usr/local/bin/pip install matplotlib) still fails with the same (Requires numpy 1.6...) message. How can I install matplotlib?

推荐答案

关于Python的注意事项

  • 如果脚本foobar.py#!/usr/bin/env python开头,那么您将始终获得OS X Python.即使MacPorts在路径中将/opt/local/bin放在/usr/bin之前,情况仍是如此.原因是MacPorts使用名称python2.7.如果要使用env但仍使用MacPorts Python,则必须编写#!/usr/bin/env python2.7.
  • 如果脚本foobar.py#!/usr/bin/python#!/opt/local/bin/python2.7显式启动,则将使用相应的Python解释器.
  • If a script foobar.py starts with #!/usr/bin/env python, then you will always get the OS X Python. That's the case even though MacPorts puts /opt/local/bin ahead of /usr/bin in your path. The reason is that MacPorts uses the name python2.7. If you want to use env and yet use MacPorts Python, you have to write #!/usr/bin/env python2.7.
  • If a script foobar.py starts explicitly with #!/usr/bin/python or with #!/opt/local/bin/python2.7, then the corresponding Python interpreter will be used.

关于点子的注意事项

  • 要为/usr/bin/python安装pip,您需要运行sudo /usr/bin/easy_install pip.然后,您呼叫pip(/usr/bin/pip中的easy_install不会安装,而在/usr/local/bin/pip中的安装)
  • 要为/opt/local/bin/python2.7安装pip,您需要运行sudo port install py27-pip.然后,您将呼叫pip-2.7.您将在/opt/local/bin中获得点子. 请注意,因为如果键入pip2.7,您将得到/usr/local/bin/pip2.7(OS X点).
  • To install pip for /usr/bin/python, you need to run sudo /usr/bin/easy_install pip. You then call pip (which will not be installed by easy_install in /usr/bin/pip, but rather in /usr/local/bin/pip)
  • To install pip for /opt/local/bin/python2.7, you need to run sudo port install py27-pip. You would then call pip-2.7. You will get the pip in /opt/local/bin. Be careful, because if you type pip2.7 you will get /usr/local/bin/pip2.7 (the OS X pip).

安装networkxmatplotlib

Installing networkx and matplotlib

  • 要为OS X Python安装networkx,请运行sudo /usr/local/bin/pip install networkx.我不知道如何在OS X Lion上安装matplotlib.可能是因为OS X在内部使用它,所以必须坚持numpy 1.5.1.
  • 要为MacPorts-Python安装networkxmatplotlib,请调用sudo pip-2.7 install networkxsudo pip-2.7 install matplotlib. matplotlib会安装很多警告,但可以通过.
  • To install networkx for the OS X Python you would run sudo /usr/local/bin/pip install networkx. I don't know how to install matplotlib on OS X Lion. It may be that OS X has to stick to numpy 1.5.1 because it uses it internally.
  • To install networkx and matplotlib for MacPorts-Python, call sudo pip-2.7 install networkx and sudo pip-2.7 install matplotlib. matplotlib installs with a lot of warnings, but it passes.

这篇关于在OS X上/usr/bin/python与/opt/local/bin/python2.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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