No module named django but it is installed
Solution 1
Probably, pip
installs packages into dist-packages
directory, which is not included into PYTHONPATH
environment variable. You have a couple of solutions:
- Create and configure
virtualenv
for your project, before usingpip
. This is the most Pythonic way -
Try to install
Django
using built-in pip module:python -m pip install django
This command should install packages into
site-packages
directory. - You may also add
dist-packages
to yourPYTHONPATH
. This question should help you: How to globally modify the default PYTHONPATH (sys.path)?
Solution 2
This error shows that Django is not installed. Installing Django should solve the problem.
In my case, Django was there in my virtualenv but while using gunicorn I was getting this error then later I realized gunicorn was dealing with my globally install python environment not my virtual environment installing Django on my global python env simply solved my issue.
pip install django
Solution 3
I got this error when using
python manage.py runserver #python version 3 was being used
Solved the problem by using:
python2 manage.py runserver #python version 2
Solution 4
You need to close the other active virtual environment in your machine if you're using virtualenv, and make sure django installed. Go to python3 interpreter and run this:
>>>from django import get_version
>>>get_version()
make sure it show you this '2.1.4'
Solution 5
I had given the dependency in requirements.txt
as Django==2.0.7
. So after activating the virtual environment, if you are receiving the message, try installing the requirements:
pip install -r requirements.txt
srk
Updated on July 09, 2022Comments
-
srk almost 2 years
I have two versions of python 2.7 and 3.4 and installed django through pip. it shows in ubuntu terminal:
$ pip freeze Django==1.6.11 $ pip --version pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7) $ python Python 2.7.9 (default, Feb 3 2016, 02:50:32) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>import django Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named django >>> import sys >>> sys.path ['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages'] >>>
Any idea??
-
gaspar over 7 yearsThis solved my problem with "No Module named django.core". Thanks!
-
awesoon over 6 yearsNote, that starting with django 2.0 you cannot use Python2: docs.djangoproject.com/en/1.11/faq/install/…
-
Bennett Garner over 5 yearsThanks! #1 didn't work (hence why I came to this question) and #2 fixed it.
-
alamin almost 5 yearsit is something to do with version... but still you dont have to downgrade it. i am running python3.7 with django 2.2.2 and inside a virtualenv.
-
DanGoodrick over 2 yearsI too was using python2 when I thought I was using 3.
python3 -m pip install django
fixed it. -
AOJ over 2 yearsThank you both for asking and answering the question!! I was going crazy with this same issue.
-
JayB about 2 yearsThis solved it for me.Thanks!