简体   繁体   English

文件“manage.py”,第 9 行,在<module> from django.core.management import execute_from_command_line ModuleNotFoundError: No module named &#39;django&#39;

[英]ile "manage.py", line 9, in <module> from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django'

#!/usr/bin/env python

import os import sys导入操作系统导入系统

if name == " main ": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.settings")如果name == " main ": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)

~ ~

anyone can explane this code.任何人都可以解释此代码。 while ı have trying to run this code with " python manage.py makemigrations " its gives an error: enter image description here虽然我试图用“ python manage.py makemigrations ”运行这段代码,但它给出了一个错误:在此处输入图像描述

but all modules in requrement.txt succsessfully loaded before.但之前 requrement.txt 中的所有模块都已成功加载。

It might be possible that django package is not installed or installed properly.可能没有安装或正确安装 django 包。

  • Create a virtual environment.创建虚拟环境。

    python3 -m venv your_venv_name python3 -m venv your_venv_name

  • Activate virtual environment.激活虚拟环境。

    source your_venv_name/bin/activate来源 your_venv_name/bin/activate

  • Install requirements.txt安装要求.txt

    pip install -r requirements.txt pip install -r requirements.txt

  • Install Django package安装 Django 包

    pip install Django点安装 Django

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM