我有一个失败的Django应用程序,因为它无法找到我安装的模块。它被称为Django-Lockdown。有人可以告诉我如何解决这个问题吗?
步骤1:启动virtualEnv并确保已安装该模块:
$ source /opt/virtualEnvs/myApp/bin/activate
(myApp)$ pip -r requirements.txt
<SNIPPED>
(myApp)$ pip show django-lockdown
---
Name: django-lockdown
Version: 1.0
Location: /opt/virtualEnvs/jobBidSite/lib/python2.7/site-packages/django_lockdown-1.0-py2.7.egg
Requires:
步骤2:运行python shell并手动导入该模块。它有效。
(myApp)$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lockdown
>>> exit()
步骤3:启动debelopment服务器。它失败了,因为它说它找不到这个模块。为什么呢?
(myApp)$ sudo python ./manage.py runserver 0.0.0.0:80
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named lockdown
答案 0 :(得分:1)
/opt/virtualEnvs/jobBidSite/lib/python2.7/site-packages
模块在你的virtualenv python包中,你使用系统python /usr/local/lib/python2.7/
来表示django。
不要使用sudo
,它正在运行系统python。