如何解决无法导入名称页(Django/wagtail)

2024-06-16 08:26:33 发布

您现在位置:Python中文网/ 问答频道 /正文

最近我一直在尝试让wagtail使用我现有的Django应用程序。我遇到了一个错误:

ImportError: No module named wagtail
unable to load app 0 (mountpoint='') (callable not found or import error)

经过多次故障排除后,我通过从以下位置复制wagtail文件夹来解决此问题:

^{pr2}$

到这里来

/opt/django/src/

解决了这个错误后,我收到了另一个关于不同模块的信息,还有一个。。。每次我将文件夹从/usr/local/lib/python2.7/dist-packages/复制到/opt/django/src/中,它最终解决了我遇到的问题并启动了uWSGI。在

现在当我访问我的应用程序主页时,我收到了这个错误

ImportError at /

cannot import name pages

    Request Method:     GET
Request URL:    http://example.com
Django Version:     1.9
Exception Type:     ImportError
Exception Value:    

cannot import name pages

Exception Location:     ./wagtail/wagtailadmin/urls/__init__.py in <module>, line 4
Python Executable:  /usr/local/bin/uwsgi
Python Version:     2.7.3
Python Path:    

['.',
 '',
 '/opt/django/src',
 '/root/.python',
 '/opt/django/env/lib/python2.7',
 '/opt/django/env/lib/python2.7/plat-linux2',
 '/opt/django/env/lib/python2.7/lib-tk',
 '/opt/django/env/lib/python2.7/lib-old',
 '/opt/django/env/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/opt/django/env/local/lib/python2.7/site-packages',
 '/opt/django/env/lib/python2.7/site-packages']

我已经检查了引用的文件(./wagtail/wagtailadmin/urls/__init__.py),它如下所示:

from django.conf.urls import url, include
from django.views.decorators.cache import cache_control

from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls
from wagtail.wagtailadmin.urls import collections as wagtailadmin_collections_urls
from wagtail.wagtailadmin.urls import password_reset as wagtailadmin_password_reset_urls
from wagtail.wagtailadmin.views import account, chooser, home, pages, tags, userbar
from wagtail.wagtailadmin.api import urls as api_urls
from wagtail.wagtailcore import hooks
from wagtail.utils.urlpatterns import decorate_urlpatterns
from wagtail.wagtailadmin.decorators import require_admin_access

冒犯的台词是第一个摇尾巴的“从”。。。在

from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls

如何解决此错误?在


Tags: djangofromimportsrcenvlibusras
2条回答

我碰到了

cannot import name pages

错误位置:

from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls

在尝试将wagtail应用部署到googleappengine时,无法在本地dev服务器上复制问题。在

我在GAE中偶尔看到的一个看似无关的错误涉及到PIL库中的导入错误。我可以通过删除PIL和pillow相关的文件夹来解决这两个错误。我不得不通过应用程序yaml由于平台特定的二进制文件,但运行pip install-t lib/-r要求,因此改为-供应商.txt导致PIL也被安装到lib文件夹中(作为Wagtail的一个依赖项)

我对wagtail设置做了一些测试。我在一个新的ubuntu14安装中进行了每个测试(每个测试都在Cloud9 IDE上的新工作区中)。在

测试1:Straight python 2.7

sudo pip install wagtail
ERRO: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

注释:输出了大量x86_64-linux-gnu-gcc: error: build/temp.linux-x86_64-2.7/libImaging/codec_fd.o: No such file or directory错误。 没用。在

测试2-使用virtualenv的python2.7

^{pr2}$

现在从他们的github https://github.com/wagtail/wagtail

pip install wagtail 
out: Successfully installed Django-1.10.7 Pillow-4.1.1 Unidecode-0.4.20 Willow-0.4 beautifulsoup4-4.5.3 django-modelcluster-3.1 django-taggit-0.22.1 django-treebeard-4.1.0 djangorestframework-3.6.2 html5lib-0.999999999 olefile-0.44 pytz-2017.2 requests-2.13.0 wagtail-1.9.1 webencodings-0.5.1
wagtail start mysite
cd mysite
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver

我不得不编辑设置/开发人员包括ALLOWED_HOSTS = ['*'],因为我在云9上。在runserver之后还需要$IP:$PORT。工作!在

Test3-使用virtualenv的python3.4

sudo pip3 install virtualenv
virtualenv -p python3 env
source env/bin/activate
pip install wagtail
Successfully installed Django-1.10.7 Pillow-4.1.1 Unidecode-0.4.20 Willow-0.4 beautifulsoup4-4.5.3 django-modelcluster-3.1 django-taggit-0.22.1 django-treebeard-4.1.0 djangorestframework-3.6.2 html5lib-0.999999999 olefile-0.44 pytz-2017.2 requests-2.13.0 wagtail-1.9.1 webencodings-0.5.1

命令的其余部分相同。而且成功了!在

测试4-python3.4没有virtualenv

sudo pip3 install wagtail
out: Successfully installed wagtail django-taggit requests Unidecode Django djangorestframework Pillow beautifulsoup4 Willow django-modelcluster django-treebeard olefile pytz
wagtail start mysite
python3 manage.py migrate
python3 manage.py createsuperuser
python3 manage.py runserver

编辑:犯了个错误。应该用python3运行,而不是python。又做了一次而且成功了!在

结论:看来你需要一个virtualenv才能在ubuntu14和python2上运行。有了python3,它可以使用virtualenv,也可以不使用virtualenv。我不能重复你的错误,但想法是一样的:它不起作用,因为它在错误的地方寻找东西。在

点评:您提到的两件事我无法测试:

I have been trying to get wagtail to work with my existing Django application

有了这么多重的依赖性(枕头、Django rest、beatifullsoup和其他我从未听说过的东西),如果它能在之前的设置中开箱即用,那就太奇怪了。我是说,Django是wagtail的附属品。所以我会换一种方式。重新开始使用wagtail并将代码移植到那里(为了社区起见,使用python3)。对我来说,最坏的还是抄袭我的程序文件。这看起来像是版本问题。试着发布所有相关内容的版本,以及重现问题的确切步骤。我是说,你在django运行的操作系统中安装了wagtail吗?在

I was having and uWSGI started.

你已经部署了你的应用了?这使事情复杂化了。如果版本和virtualenv不能解决您的问题,社区需要deploy的设置细节。你还没有提到你的操作系统。在

我希望这有帮助!祝你好运!在

相关问题 更多 >