简体   繁体   中英

Couldn't import Django

I am trying to run django from virtualenv but i am getting this error:

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:

ModuleNotFoundError: No module named 'django.core'

i checked if django is installed.

(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?

If you are are having multiple python versions installed, then you might face this issue. If you are using python manage.py , try using python3 manage.py instead.

I had multiple versions of Phyton installed (Phyton2.7&Python3.7). Uninstalling Python 2.7 solved the problem.

Uninstall Python from your computer and install latest version and then activate virtual environment in your directory.And then try again.

You can use this link as well- Click here !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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