在OS X上/usr/bin/python与/opt/local/bin/python2.7 [英] /usr/bin/python vs /opt/local/bin/python2.7 on OS X
问题描述
您能否阐明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?
在安装networkx
和matplotlib
时,我很难与/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 namepython2.7
. If you want to useenv
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 runsudo /usr/bin/easy_install pip
. You then callpip
(which will not be installed byeasy_install
in/usr/bin/pip
, but rather in/usr/local/bin/pip
) - To install
pip
for/opt/local/bin/python2.7
, you need to runsudo port install py27-pip
. You would then callpip-2.7
. You will get the pip in/opt/local/bin
. Be careful, because if you typepip2.7
you will get/usr/local/bin/pip2.7
(the OS X pip).
安装networkx
和matplotlib
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安装
networkx
和matplotlib
,请调用sudo pip-2.7 install networkx
和sudo pip-2.7 install matplotlib
.matplotlib
会安装很多警告,但可以通过.
- To install
networkx
for the OS X Python you would runsudo /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 tonumpy 1.5.1
because it uses it internally. - To install
networkx
andmatplotlib
for MacPorts-Python, callsudo pip-2.7 install networkx
andsudo 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屋!