【问题标题】:ImportError: No module named tzwhereImportError:没有名为 tzwhere 的模块
【发布时间】:2016-04-06 06:59:06
【问题描述】:

我使用 Python 2.7 在 AWS EC2 实例上安装了 tzwhere,并且:

pip install tzwhere

当我在“/opt/python/run/venv/lib/python2.7/site-packages”的 Python 中导入它时,它的安装位置可以正常工作,但我无法在其他任何地方导入它。我在系统路径中添加了“/opt/python/run/venv/lib/python2.7/site-packages”,但没有帮助。 如果你能指导我如何解决这个问题,我将不胜感激。

让我解释更多细节:我正在 Amazon Elastic Beanstalk 上部署一个 Django 1.6 项目。部署项目时,我只需要导入一次 tzwhere。所以我在setting.py中导入了它。当我激活虚拟环境时(在this post 中解释),我可以在 python 中导入 tzwhere,但是当我运行时:

sudo python manage.py schemamigration southtut --initial

它返回以下错误消息:

ImportError: Could not import settings 'JoinWikipedians.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named tzwhere

当我停用虚拟环境时,导入 tzwhere 会返回导入错误。另外,在任何python环境下,当我使用:

sys.path.append('/opt/python/run/venv/lib/python2.7/site-packages')

我可以导入 tzwhere,但在我的 setting.py 中导入 tzwhere 之前的相同代码没有帮助。

【问题讨论】:

  • '/opt/python/run/venv/lib/python2.7' 在 sys.path 中。
  • 尝试设置 $PYTHONPATH?
  • 是的,我终于找到了解决方案,我把它写成了答案。无论如何,谢谢您的关心。

标签: python amazon-web-services import module pytz


【解决方案1】:

我找到了解决方案。问题是 AWS EC2 在 pip install tzwhere 上有一些问题。每当我尝试安装它时,它都会返回内存错误消息。我完全删除了它并安装了 pytzwhere,使用:

git clone --recursive https://github.com/pegler/pytzwhere.git
python setup.py install

现在可以完美运行了。

【讨论】:

    猜你喜欢
    • 2013-03-11
    • 2012-12-07
    • 2012-05-23
    • 2019-07-29
    • 2015-07-04
    • 2014-03-15
    • 2017-12-29
    • 2014-09-12
    • 2017-05-09
    相关资源
    最近更新 更多