Forums

Error running WSGI application after upgrade system image

Hello, I am has just updated my website from fishnchips to haggis. At the first time, everything is cool. However, the website is down. I got the following error message from error log.

2024-11-22 18:54:37,499: Error running WSGI application
2024-11-22 18:54:37,501: ImportError: No module named django.core.wsgi
2024-11-22 18:54:37,501:   File "/var/www/MY-SITE_wsgi.py", line 23, in <module>
2024-11-22 18:54:37,501:     from django.core.wsgi import get_wsgi_application
2024-11-22 18:54:37,501: ***************************************************
2024-11-22 18:54:37,501: If you're seeing an import error and don't know why,
2024-11-22 18:54:37,501: we have a dedicated help page to help you debug: 
2024-11-22 18:54:37,501: https://help.pythonanywhere.com/pages/DebuggingImportError/
2024-11-22 18:54:37,501: ***************************************************

I check the installation about Django it has been installed. Then I checked the link about ImportError above but it seems not the same case as mine.
The code in. /var/www/MY-SITE_wsgi.py is auto-generated, and I checked my settings.py but found nothing related. It's my bad that I didn't follow the instruction to backup the virtualenv before system image upgrading, because the site only used Django and SQLite. So what can I do to get the website back to normal again? Thank you very much.

Which python version did you use to create your new virtualenv and which python version does your app use?

@nkahr, my app use 2.7 and now it switched to 3.10 in the new system image.

The version that you use to create your virtualenv needs to match the version of your web app.

I am facing the exact same issue! What is the solution to this?

I am facing the exact same issue! What is the solution to this?

What is the full error message that you're seeing in your logs?

@giles the log is the same as I wrote above, and keep repeating.

Make sure that your web app is using the venv where django is installed.

@fjl I used PythonAnywhere for a long time, and my server does not have the virtualenv installed. So I am using the server env. I ran pip show django in bash, I saw my Django version. I also upgrade my Django to the latest version in case the version of Django is not compatible to the python version. However, I cannot see the a change after doing this and reload my web app.

What is the exact error that you're getting with the current setup? It should be at the bottom of your website's error log.

@giles the error is the same as the first post.

It looks like you use Python 2.7 for your web app which doesn't have django preinstalled on the system image you currently use (i.e. the most recent one, haggis).

@pafk I did use Python 2.7 and Django, without virtualenv in my previous system image fishnchips. I also check the current installed Django in my current system image haggis. pip show django and I get the version of my installed Django, which is 4.0.6. Maybe the version is not update to date to suit the system iamge of Python 3.10, I ran pip install --upgrade Django to upgrade me Django to 5.1.4. However all this trial cannot fix my problem.

pip on its own will show you the installed packages for your default Python version (3.10 for your account -- see this page. If you want to see what's installed for Python 2.7, or to install something, then you should use pip2.7.