Forums

Django 1.7 - No module named importlib

Hi,

I was hoping to be able to quickly restart a webapp (Django 1.7 build - the webapp hasn't been activated for some months).

But having hit Reload button on the web page, nothing's happened.

I think the server log below is telling me it can't find the app because importlib or import_module is missing/deprecated.

However, I couldn't find the file where this line of code resides in my directory.

Any ideas on how to fix this?

Thanks in advance,

Chris

2018-08-16 03:48:26 Traceback (most recent call last):
2018-08-16 03:48:26   File "/bin/user_wsgi_wrapper.py", line 29, in <module>
2018-08-16 03:48:26     
2018-08-16 03:48:26 from importlib import import_module
2018-08-16 03:48:26 ImportError
2018-08-16 03:48:26 : 
2018-08-16 03:48:26 No module named importlib
2018-08-16 03:48:26 
2018-08-16 03:48:26 unable to load app 0 (mountpoint='') (callable not found or import error)
2018-08-16 03:48:26 *** no app loaded. going in full dynamic mode ***
2018-08-16 03:48:26 *** uWSGI is running in multiple interpreter mode ***
2018-08-16 03:48:26 gracefully (RE)spawned uWSGI master process (pid: 1)
2018-08-16 03:48:26 spawned uWSGI worker 1 (pid: 2, cores: 1)
2018-08-16 03:48:26 spawned uWSGI worker 2 (pid: 3, cores: 1)
2018-08-16 03:48:26 metrics collector thread started
2018-08-16 03:48:26 spawned 2 offload threads for uWSGI worker 2
2018-08-16 03:48:26 spawned 2 offload threads for uWSGI worker 1
2018-08-16 03:48:30 --- no python application found, check your startup logs for errors ---

Hmm, that's odd -- importlib is build into Python, so it certainly should be importable. I see you're using a virtualenv -- what happens if you start a bash console in the virtualenv (using the link on the "Web" page), then run python and do this:

>>> import importlib
>>> importlib.__file_

...?

If you get a similar "no module named importlib" then it's possible that your virtualenv has somehow become broken, so you should re-create it.

Thanks Giles,

I do indeed get some weird stuff just on trying the import (as per pic below)

So I'll try to recreate the virtualenv.

Thanks again for the advice!

From my Bash

It looks like you were running that code inside bash (that is, you didn't start Python first) so that would explain the oddity -- still, I do think the venv is the problem so let's see what happens if you re-create it.

Yes, sorry about that Giles (I'm coming back to this after about 18 months layoff and have forgotten what little I knew back then)

Good advice though, thanks - I did recreate the virtualenv and things are moving.

For some reason I also had to pip install (and add to my requirements.txt):

(i) django-storage

(ii) mysqlclient

Btw, this is all on Django 1.7 and Python 2.7.

So the site is now up, but if I were to guess, I'd say the page templates are not working.

That is, I can see the header and footer, but no page contents are showing, just an access error message (in pic below).

I looked through my Access, Error and Service logs, but couldn't see anything about it.

I'm somewhat suspicious about that message though.

I doubt that its a PythonAnywhere engineers problem, but more likely to be mine.

Any advice on how to resolve this new issue?

Thanks again

Chris

(PS. wasn't sure whether to put this into a new topic, so left it running in this thread)

My website

That's quite weird- if your site is showing some aspects (eg: crosstech partners), then it seems like it got to your site correctly, and perhaps you are catching some errors and writing it somewhere yourself.

Ok, I'll follow that train of thought and see if I can find some errors I might have inadvertantly coded.

Thanks for the comment.

It might be worth switching on the DEBUG flag in your Django settings, just in case that's suppressing some level of error logging -- or perhaps check out the LOGGING settings, in case there's any indication there as to where the error messages might be being sent.

Thanks Giles & Conrad, it seems to be sorted now.

The DEBUG flag helped to spot that it was a database referencing problem.

Specifically, I changed Host in the Database parameters in the Settings file from:

'HOST': 'mysql.server'

to:

'HOST': 'koitaki.mysql.pythonanywhere-services.com',

All good now.

Many thanks again for your help & advice...as always, very much appreciated!

Chris

Ah, that would make sense! If it's an old website then it must have been set up to access your database using the hostname that we originally used -- that changed a couple of years back, but you said earlier that it's been inactive for a while.