安装并获取python模块以在mac上工作

时间:2015-11-06 01:55:22

标签: python macos python-2.7

我尝试在运行El Capitan的mac上安装twilio模块pip,它显示以下内容:

~ $ pip install twilio
Requirement already satisfied (use --upgrade to upgrade): twilio in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): httplib2>=0.7 in /Library/Python/2.7/site-packages (from twilio)
Requirement already satisfied (use --upgrade to upgrade): six in /Library/Python/2.7/site-packages (from twilio)
Requirement already satisfied (use --upgrade to upgrade): pytz in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from twilio)
 ~ $ python
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import twilio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/twilio/__init__.py", line 11, in <module>
    from .rest.exceptions import TwilioRestException
  File "/Library/Python/2.7/site-packages/twilio/rest/__init__.py", line 1, in <module>
    from .base import set_twilio_proxy
  File "/Library/Python/2.7/site-packages/twilio/rest/base.py", line 6, in <module>
    from twilio.rest.resources import Connection
  File "/Library/Python/2.7/site-packages/twilio/rest/resources/__init__.py", line 1, in <module>
    from .util import (
  File "/Library/Python/2.7/site-packages/twilio/rest/resources/util.py", line 5, in <module>
    import pytz
ImportError: No module named pytz

然后我尝试安装pytz,它说我已经拥有它了:

~ $ pip install pytz
Requirement already satisfied (use --upgrade to upgrade): pytz in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

是否是因为我的mac上有不同的Python发行版?我搜索了一段时间,人们说pip只安装到默认的Python,最好使用MacPort,Homebrew和virtualenv来管理python发行版。但我真正想要做的就是直接解决这个特殊问题。我跑了type -a python我从另一篇文章中看到它产生了,

~ $ type -a python
python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
python is /usr/local/bin/python
python is /usr/bin/python

它们都是Python 2.7.10,前两个似乎是相同的。 (我发现它们是Python.org Python。)

我不知道如何在终端之间切换它们,或者为它们分别安装包。我想这是一个常见问题,但我无法用一个小时的搜索来解决它。

要清楚,我在这里添加了更多信息,

~ $ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

~ $ /Library/Frameworks/Python.framework/Versions/2.7/bin/python
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

~ $ /usr/local/bin/python
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

~ $ /usr/bin/python
Python 2.7.10 (default, Aug 22 2015, 20:33:39) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

1 个答案:

答案 0 :(得分:1)

您正在使用的pip实例可能与系统Python相关联,而python命令正在调用python.org Python。避免此类不匹配的一种方法是通过用于调用pip的命令调用python,在这种情况下:

python -m pip install twilio

这将确保您使用正确的pip并将软件包安装到正在使用的Python的正确位置。