2015-05-13 169 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