【发布时间】: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