manage.py报错 ModuleNotFoundError No module named 'django'
出现场景:我在Windows系统写好了一个django项目,复制到Ubuntu中,运行python3 manage.py migrate
一切正常,但运行python3 manage.py runserver
报错:
Traceback (most recent call last):
File “manage.py”, line 11, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named ‘django’The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “manage.py”, line 22, in
main()
File “manage.py”, line 13, in main
raise ImportError(
ImportError: Couldn’t import Django. Are you sure it’s installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
在终端中进入python3,import django
也不报错。网上很多方法,要么需要安装虚拟环境太复杂,要么完全无效。我突然想到可能是Linux环境下创建项目时的manage.py
有不同,于是创建项目django-admin startproject my_project
,提示:
安装完成以后,神奇地发现,python3 manage.py runserver
成功运行了!