在Mac上安装pytz

时间:2015-05-13 20:23:58

标签: python macos pip pytz

Django通知我" ImportError:没有名为pytz"的模块,但是当我使用pip来安装它时,我得到了这个结果:

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

由于

1 个答案:

答案 0 :(得分:7)

/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,以确保在流程python上首先找到正确的pipPATH个实例。