【问题标题】:why do I receive an error when I want to start my django app?当我想启动我的 django 应用程序时,为什么会收到错误消息?
【发布时间】:2020-06-10 19:23:40
【问题描述】:

当我使用“manage.py runserver”命令启动我的 dajngo 应用程序时,我收到错误消息:


`Traceback (most recent call last):
  File "manage.py", line 8, in 
    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 10, in 
    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?`

但是,我刚刚验证了所有要求的安装,并且我的虚拟环境已很好地激活。所以我不知道为什么它不起作用。

感谢您的所有回答!

【问题讨论】:

  • 您可能需要运行python manage.py runserver。否则,您能否提供来自pip freeze 的输出
  • 如果你只运行python,然后'import python'会发生什么?
  • 你在使用 virtualenv 吗?如果是这样,它是否“激活”?在这两种情况下,请确保已安装 django,您可以尝试 pip install django 或者如果您有 requirements.txt 文件,pip install -r requirements.txt
  • 你激活venv后,可以输入python --version
  • @mattyx17 我试着只输入python manage.py runserver,但想法相同,这里是pip freeze 的提供:apturl==0.5.2 blinker==1.4 Brlapi==0.7.0 certifi==2019.3.9 chardet==3.0.4 command-not-found==0.3 cryptography==2.8 cupshelpers==1.0 dbus-python==1.2.16 defer==1.0.6 defusedxml==0.5.0 distro==1.4.0 distro-info===0.23ubuntu1 Django==2.2 django-debug-toolbar==1.11

标签: python django


【解决方案1】:

你可以试试this

您需要安装 Django。您可能忘记在环境处于活动状态时安装它。

【讨论】:

  • 感谢您的回答,但不是这样,因为当我尝试安装 django 时,我收到一条错误消息,指出 django 已安装,并且当我转到“站点包”时在环境中的文件夹中,有一个名为 django 的文件夹和另一个名为 Django-2.2.dist-info 的文件夹,每个文件夹中都有一个 'init.py' 文件。
【解决方案2】:

在终端运行以下命令安装 Django:

pip install Django

在此之后,运行您的项目。

【讨论】:

  • 这个命令没有任何改变,因为 django 已经安装:Requirement already satisfied: Django in /usr/local/lib/python3.8/dist-packages (2.2) Requirement already satisfied: pytz in /usr/local/lib/python3.8/dist-packages (from Django) (2018.9) Requirement already satisfied: sqlparse in /usr/local/lib/python3.8/dist-packages (from Django) (0.3.0)
猜你喜欢
  • 2015-01-25
  • 1970-01-01
  • 2023-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多