ImportError:没有名为“ django”的模块,ImportError:无法导入Django

时间:2018-07-09 01:52:06

标签: python django-rest-framework

我是python的新手,运行此命令时出现此错误

plutus@plutus-probook /var/www/html/python_learn/myproject $ python manage.py startapp webapp
Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    import django
ImportError: No module named 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 17, in <module>
    "Couldn't import Django. Are you sure it's installed and "
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?

如果我尝试安装django,那么结果就是

plutus@plutus-probook /var/www/html/python_learn/myproject $ pip install django
Requirement already satisfied: django in /usr/local/lib/python2.7/dist-packages (1.11.6)
Requirement already satisfied: pytz in /usr/local/lib/python2.7/dist-packages (from django) (2017.2)

1 个答案:

答案 0 :(得分:1)

这可能是因为您可能有multiple versions of python and pip lying around。试试这个

python -m pip install django

这将确保您为在终端上调用python时所调用的python版本安装django。