工作,我試圖用pip
上運行埃爾卡皮坦我的Mac上安裝模塊twilio
並呈現如下:安裝和得到一個Python模塊在Mac
~ $ 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)。
我不知道如何在終端之間切換它們,或者pip分別爲它們安裝軟件包。我想這是一個普遍的問題,但我無法通過一小時的搜索解決它。
要清楚,我加入了一些更多的信息在這裏,
~ $ 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.
>>>
非常感謝,它做到了!但我仍然有些疑惑。有沒有辦法直接檢查當前與哪個'python''pip關聯? –
'pip'命令是一個Python腳本。您可以檢查它的「shebang」行來查看直接調用時(而不是通過「python -m」)將使用的Python解釋器的路徑。如果你使用的是POSIX兼容的shell,比如'bash',那麼下面的命令應該可以工作:'head -1 $(type -p pip)' –