How to resolve cannot import name pages (django/wagtail)
Asked Answered
A

2

6

Recently I have been trying to get wagtail to work with my existing Django application. I was experiencing an error: -

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

After much troubleshooting I managed to fix this, by copying the folder wagtail from:

/usr/local/lib/python2.7/dist-packages/

into here

/opt/django/src/

Having resolved this error, I received another about a different module, and another... each time I copied the folder from /usr/local/lib/python2.7/dist-packages/ into /opt/django/src/ and it eventually resolved the issues I was having and uWSGI started.

Now when I access the homepage of my app, I receive this error

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']

I have checked the file referenced (./wagtail/wagtailadmin/urls/__init__.py) and it looks like this:

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

The offending line is the first wagtail 'from' ...

from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls

How can I resolve this error?

Additament answered 28/3, 2017 at 16:46 Comment(4)
I am also having same issue. Let me if you solved this issue.Lynnelle
Instead of copying files from /usr/local/lib/python2.7/dist-packages/ You should use a virtualenv and use pip to install wagtail.Gott
Did but same problem. I think the problem is related to nginx. Its showing 502 bad gateway.Lynnelle
what is your python version?Utilitarian
C
5

I've ran a few tests on wagtail setup. I made each test in a fresh Ubuntu 14 install (each test in a new workspace on Cloud9 IDE).

Test 1: Straight python 2.7

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

Comment: Lots of x86_64-linux-gnu-gcc: error: build/temp.linux-x86_64-2.7/libImaging/codec_fd.o: No such file or directory errors were output. Didn't work.

Test 2 - Python 2.7 with virtualenv

sudo pip install virtualenv
virtualenv env 
source env/bin/activate

Now from their 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

I had to edit the settings/dev.py and include ALLOWED_HOSTS = ['*'] because I'm on cloud 9. Also needed the $IP:$PORT after runserver. WORKED!

Test3 - Python 3.4 with virtualenv

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

Rest of the command are the same. And it WORKED!

Test 4 - Python 3.4 no 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

EDIT: Made a mistake. Should've run with python3, not python in this case. Did it again and worked!

Conclusion: Looks that you need a virtualenv for this to work on Ubuntu 14 and python2. With python3 it works with and without virtualenv. I could not reproduce your error, but the idea is the same: it does not work because it looks for stuff in the wrong place.

Comments: There are two things you mention that I could not test:

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

With this big amount of heavy dependencies, (Pillow, Django rest, beatifullsoup and others I've never heard of) it would be strange if it worked out of the box with a previous setup. I mean, Django is a dependency for wagtail. So I would try the other way around. Start fresh with wagtail and port your code there (with python3 for the sake of the community ;) ). Also this manual copy of files is like programmers worst nightmare (at least to me). This looks like a version problem. Try to post the versions of everything involved, and the exact steps to reproduce the issue. I mean, did you pip install wagtail in the operating system that django was running?

I was having and uWSGI started.

So you have your app deployed already? This complicates things. If versions and virtualenv do not solve your problem, community needs setup details of deploy. Also you haven't mentioned your operational system.

I hope this helps! Good Luck!

Chincapin answered 3/5, 2017 at 0:25 Comment(0)
G
1

I ran into the

cannot import name pages

error at:

from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls

while trying to deploy a wagtail app to Google App Engine and could not duplicate the problem on my local dev server.

A seemingly unrelated error that I saw only intermittently in GAE involved an import error in the PIL library. I was able to resolve BOTH errors by deleting PIL and pillow related folders from my vendored packages in my /lib directory. I had to import PIL through the app.yaml file instead due to the platform specific binary, but running pip install -t lib/ -r requirements-vendor.txt caused PIL to be installed into the lib folder as well (as a dependency of Wagtail)

Grampositive answered 7/6, 2017 at 23:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.