ModuleNotFoundError: No module named 'django'

不羁的心 提交于 2020-12-26 08:27:40

问题


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


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/46413676/modulenotfounderror-no-module-named-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!