简体   繁体   English

无法导入 Django

[英]Couldn't import Django

I am trying to run django from virtualenv but i am getting this error:我正在尝试从 virtualenv 运行 django 但我收到此错误:

Error错误

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.core'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 17, in main
    ) from exc
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtu?
(

when i imported django from python shell,i got this:当我从 python shell 导入 django 时,我得到了这个:

ModuleNotFoundError: No module named 'django.core'

i checked if django is installed.我检查了是否安装了 django。

(welpieenv) root@li2180-35:~/welpie# source welpieenv/bin/activate
(welpieenv) root@li2180-35:~/welpie# pip install django
Requirement already satisfied: django in ./welpieenv/lib/python3.7/site-packages (3.1.6)
Requirement already satisfied: sqlparse>=0.2.2 in ./welpieenv/lib/python3.7/site-packages (from django) (0.4.1)
Requirement already satisfied: asgiref<4,>=3.2.10 in ./welpieenv/lib/python3.7/site-packages (from django) (3.3.1)
Requirement already satisfied: pytz in ./welpieenv/lib/python3.7/site-packages (from django) (2021.1)
(welpieenv) root@li2180-35:~/welpie# pip3 install django
Requirement already satisfied: django in ./welpieenv/lib/python3.7/site-packages (3.1.6)
Requirement already satisfied: sqlparse>=0.2.2 in ./welpieenv/lib/python3.7/site-packages (from django) (0.4.1)
Requirement already satisfied: pytz in ./welpieenv/lib/python3.7/site-packages (from django) (2021.1)
Requirement already satisfied: asgiref<4,>=3.2.10 in ./welpieenv/lib/python3.7/site-packages (from django) (3.3.1)

As you guys can see virtualenv is activated.Why am i getting this error?如你们所见,virtualenv 已激活。为什么会出现此错误?

If you are are having multiple python versions installed, then you might face this issue.如果您安装了多个 python 版本,那么您可能会遇到此问题。 If you are using python manage.py , try using python3 manage.py instead.如果您使用的是python manage.py ,请尝试改用python3 manage.py

I had multiple versions of Phyton installed (Phyton2.7&Python3.7).我安装了多个版本的 Phyton(Phyton2.7&Python3.7)。 Uninstalling Python 2.7 solved the problem.卸载 Python 2.7 解决了这个问题。

Uninstall Python from your computer and install latest version and then activate virtual environment in your directory.And then try again.从您的计算机上卸载 Python 并安装最新版本,然后在您的目录中激活虚拟环境。然后重试。

You can use this link as well- Click here !您也可以使用此链接 - 单击此处

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

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