为什么我在尝试启动 Django 应用程序时收到 'no module named wagtail' 错误

Why am I receiveing 'no module named wagtail' error when I try to launch django app

我有一个现有的 Django 项目。我想用它来使用 Wagtail。 我已按照此处的说明进行操作: http://docs.wagtail.io/en/v1.9/getting_started/integrating_into_django.html

然而,当我尝试启动我的应用程序时,我从 uWSGI 收到以下错误消息:-

    *** Operational MODE: preforking ***
    Traceback (most recent call last):
      File "./core/wsgi.py", line 16, in <module>
        application = get_wsgi_application()
      File "/opt/django/env/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
        django.setup()
      File "/opt/django/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "/opt/django/env/lib/python2.7/site-packages/django
/apps/registry.py", line 85, in populate
        app_config = AppConfig.create(entry)
      File "/opt/django/env/lib/python2.7/site-packages/django/apps/config.py", line 116, in create
        mod = import_module(mod_path)
      File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
        __import__(name)
    ImportError: No module named wagtail
    unable to load app 0 (mountpoint='') (callable not found or import error)

ImportError: No module named wagtail

不过我已经安装了wagtail。

我找到了这个https://github.com/wagtail/wagtaildemo/issues/32

哪个建议

Please can you run pip freeze and paste the output here?

我有 运行 点冻结,这是结果:-

Django==1.9.12
Pillow==3.0.0
Unidecode==0.4.20
Willow==0.4
argparse==1.2.1
assert-exists==0.0.0
backports.ssl-match-hostname==3.5.0.1
beautifulsoup4==4.5.3
caller-module==0.0.0
cp==0.0.0
distribute==0.7.3
django-appconf==1.0.1
django-autocomplete-light==3.2.1
django-compat==1.0.8
django-compressor==1.6
django-dual-authentication==1.0.0
django-hijack==2.0.1
django-htmlmin==0.8.0
django-ipware==1.1.2
django-mathfilters==0.3.0
django-modelcluster==3.0.1
django-taggit==0.22.0
django-treebeard==4.1.0
django-widget-tweaks==1.4.1
djangorestframework==3.6.2
evernote==1.25.1
html5lib==0.9999999
httplib2==0.9.2
not==1.7
oauth2==1.9.0.post1
olefile==0.44
pbr==1.8.1
public==0.0.0
publicsuffix==1.1.0
python-dateutil==2.2
pytz==2015.7
requests==2.13.0
setupfiles==0.0.0
simplejson==3.10.0
six==1.10.0
slackclient==1.0.5
stevedore==1.10.0
svn==0.3.36
uWSGI==2.0.11.2
url==0.1.5
virtualenv==13.1.2
virtualenv-clone==0.2.6
virtualenvwrapper==4.7.1
wagtail==1.9
webencodings==0.5
websocket-client==0.40.0
wheel==0.24.0
wsgiref==0.1.2

上面 link 中的下一个故障排除步骤说明:-

What do you get if you enter the following lines at the python command line?

import wagtail; wagtail import wagtail.wagtailadmin; wagtail.wagtailadmin import wagtail.wagtailforms; wagtail.wagtailforms

这是我 运行 python 中的那些命令时的结果:

Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wagtail; wagtail
<module 'wagtail' from '/usr/local/lib/python2.7/dist-packages/wagtail/__init__.pyc'>
>>> import wagtail.wagtailadmin; wagtail.wagtailadmin
<module 'wagtail.wagtailadmin' from '/usr/local/lib/python2.7/dist-packages/wagtail/wagtailadmin/__init__.pyc'>
>>> import wagtail.wagtailforms; wagtail.wagtailforms
<module 'wagtail.wagtailforms' from '/usr/local/lib/python2.7/dist-packages/wagtail/wagtailforms/__init__.pyc'>
>>>

为什么我会收到 'no module named wagtail' 错误?

您似乎安装了两个 python 2.7,一个是内置的,一个是手动安装的。显示导入错误的那个使用 python located at:

/usr/lib/python2.7/

而您安装模块的位置位于此处:

/usr/local/lib/python2.7/

您需要将 wagtail 安装到第一个 python 或更改 Django 项目以使用第二个 python。