Pierino
Pierino

Reputation: 103

ModuleNotFoundError: No module named 'django'

I'm trying make online a project but there is an error i can't solve myself. I already installed django but the server give me this error. Virtualenv is also active.

2017-09-25 20:10:27,471: ***************************************************
2017-09-25 20:10:30,892: Error running WSGI application
2017-09-25 20:10:30,893: ModuleNotFoundError: No module named 'django'
2017-09-25 20:10:30,893:   File "/var/www/asd1_pythonanywhere_com_wsgi.py", line 17, in <module>
2017-09-25 20:10:30,893:     from django.core.wsgi import get_wsgi_application
2017-09-25 20:10:30,893: ***************************************************
2017-09-25 20:10:30,893: If you're seeing an import error and don't know why,
2017-09-25 20:10:30,894: we have a dedicated help page to help you debug: 
2017-09-25 20:10:30,894: https://help.pythonanywhere.com/pages/DebuggingImportError/
2017-09-25 20:10:30,894: ***************************************************

Wsgi file is it:

    import os
import sys


path = '/home/asd1/mysite'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Hosting is pythonanywhere.com

Upvotes: 10

Views: 37091

Answers (4)

trustidkid
trustidkid

Reputation: 557

The error means Django is not installed. You can install Django with the following command

python -m pip install Django

Upvotes: 4

JCQian
JCQian

Reputation: 879

This might be answered many times, but recently I upgraded my ubuntu 18.04 to 19.10, and without changing any other thing, my running django server stopped running with this error: ModuleNotFoundError: No module named 'django'. I repeated the same install, python3 -m pip install django and it didn't help. Finally somebody else told me to use

sudo python3 -m pip install django

because I run the server with sudo python3 manage.py runserver 0.0.0.0:80, which actually worked for me.

Upvotes: 1

Maelstrom
Maelstrom

Reputation: 453

Did you follow the instruction on how to edit your wsgi? From the help page:

Edit your WSGI file

One thing that's important here: your Django project (if you're using a recent version of Django) will have a file inside it called wsgi.py. This is not the one you need to change to set things up on PythonAnywhere -- the system here ignores that file.

Instead, the WSGI file to change is the one that has a link inside the "Code" section of the Web tab -- it will have a name something like /var/www/yourusername_pythonanywhere_com_wsgi.py or /var/www/www_yourdomain_com_wsgi.py.

Upvotes: 0

monte
monte

Reputation: 555

You need to install Django. You may have forgotten to install it while the environment was active.

You can learn how to do this here.

This also could be because you have called your project a name such as "django" which would conflict with the installed packages.

Upvotes: 5

Related Questions