无法安装 Django,运行服务器错误

Posted

技术标签:

【中文标题】无法安装 Django,运行服务器错误【英文标题】:Can't install Django, runserver error 【发布时间】:2017-12-03 00:42:44 【问题描述】:

所以我一直在尝试设置 Django,就像 thenewboston(又名 Bucky Roberts)在 youtube 上展示的那样。这是链接:https://www.youtube.com/watch?v=CHjXtRrhqxc&index=2&list=PL6gx4Cwl9DGBlmzzFcLgDhKTTfNLfX1IK 但是当我运行服务器时,我会收到类似

的错误
PS C:\Users\Dante\Desktop> django-admin startproject MyProject1
PS C:\Users\Dante\Desktop> cd .\MyProject1
PS C:\Users\Dante\Desktop\MyProject1> ls


    Directory: C:\Users\Dante\Desktop\MyProject1


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2017-06-29     12:17                .idea
d-----       2017-06-29     12:13                MyProject1
-a----       2017-06-29     12:13            830 manage.py


PS C:\Users\Dante\Desktop\MyProject1> python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ModuleNotFoundError: 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
ModuleNotFoundError: 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?
PS C:\Users\Dante\Desktop\MyProject1> python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ModuleNotFoundError: 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
ModuleNotFoundError: 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 吗?如果没有,请先这样做。假设你已经安装了 pip(一个 Python 包管理器),那么你可以使用这个命令 pip install Dango 来安装 Django。但首先你可以检查 Django 是由pip show Django 还是pip list 安装的。 将代码粘贴为 sn-p 而不是屏幕截图。您是如何创建项目的?你在使用虚拟环境吗? 请将您的图片替换为 text。图片搜不到,大家都看不到……见meta.***.com/questions/285551/… 【参考方案1】:

创建虚拟环境(virtualenv venv)。激活该 virtualenv(源 venv/bin/activate)。然后安装django。

【讨论】:

以上是关于无法安装 Django,运行服务器错误的主要内容,如果未能解决你的问题,请参考以下文章

解决django项目在ubuntu系统上无法安装mysqlclient

如果不安装django.contrib.messages.middleware.MessageMiddleware,则无法添加消息

无法安装 Django

无法在其他系统中运行 django 项目

Django 已安装但无法运行 - ModuleNotFoundError: No module named 'django'

尝试启动应用程序时无法导入 Django 错误