pytz在Mac上安装

凯西·珀金斯(Casey Perkins)

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

谢谢

内德·迪利

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras是与Apple提供的Python 2.7(/usr/bin/python2.7关联的位置从回溯中无法得知,但很有可能Django是在不同的Python 2.7实例下运行的,也许与from链接/usr/local/bin当有多个Python实例并且您pip直接从命令行使用时,会出现这类问题确保pip为使用的每个Python安装了一个版本并且,为确保您使用的正确实例pip,可以通过以下方式调用它:

python -m pip install pytz

替换用于python运行Django的相同路径。

另一种方法是始终使用激活的方法virtualenv,该方法应确保首先在流程中找到权限pythonpip实例PATH

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章