2015-05-13 222 views
2

的Django告訴我的「導入錯誤:沒有模塊名爲pytz」,但是當我去使用PIP安裝它,我得到這樣的結果:pytz在Mac上安裝

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

是否有可能是在尋找錯誤的位置,或者我需要嘗試在別的地方安裝它?

以下是完整的堆棧跟蹤:

Internal Server Error: /basicloginwebservice/ 
Traceback (most recent call last): 
    File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 103, in get_response 
    resolver_match = resolver.resolve(request.path_info) 
    File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 321, in resolve 
    sub_match = pattern.resolve(new_path) 
    File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 223, in resolve 
    return ResolverMatch(self.callback, args, kwargs, self.name) 
    File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 230, in callback 
    self._callback = get_callable(self._callback_str) 
    File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 29, in wrapper 
    result = func(*args) 
    File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 97, in get_callable 
    mod = import_module(mod_name) 
    File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module 
    __import__(name) 
    File "/Users/<redacted>/django/<redacted>/<redacted>/views.py", line 3, in <module> 
    import pytz 
ImportError: No module named pytz 

由於

回答

6

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras與Apple提供的Python 2.7(/usr/bin/python2.7)相關聯的位置。從回溯中無法判斷,但是Django可能在Python 2.7的另一個實例下運行,可能與/usr/local/bin有關。如果有多個Python實例,並且您直接從命令行使用pip,則可能會出現這些問題。確保您爲每個正在使用的Python安裝了pip版本。而且,爲了確保您使用的pip正確的實例,你可以調用這樣說:

python -m pip install pytz

替代python用來運行Django的相同的路徑。

另一種方法是始終使用激活virtualenv應確保正確pythonpip實例首次發現的過程PATH