How to Solve Error Message ModuleNotFoundError : No module named ‘django’

Posted on

This article will display how to solve a specific error message. The error message is present after the execution of a certain command. The command execution in the Windows Command Prompt triggers an error. That command execution is ‘python manage.py runserver where the main purpose is to run a Django-based application. The following it the execution of the command in a python environment :

(myenv) C:\python\django\project\apps>python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 10, in main
    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 21, in 
    main()
  File "manage.py", line 12, in main
    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?
(myenv) C:\python\aarav-tech-django-course\ems>

Apparently, there is no module with the name of ‘django’. So,check it first by listing all of the available module in the current python environment by typing the following command :

(myenv) C:\python\django\project\apps>pip list
Package           Version
----------------- ---------
beautifulsoup4    4.9.3
blis              0.4.1
bs4               0.0.1
catalogue         1.0.0
certifi           2020.6.20
chardet           3.0.4
click             7.1.2
cycler            0.10.0
cymem             2.0.3
html5lib          1.1
id-ud-tag-dep-ner 1.0.0
idna              2.10
joblib            0.17.0
kiwisolver        1.2.0
lxml              4.5.2
matplotlib        3.3.2
murmurhash        1.0.2
nltk              3.5
numpy             1.19.2
pandas            1.1.3
Pillow            7.2.0
pip               20.2.3
plac              1.1.3
preshed           3.0.2
psycopg2          2.8.6
psycopg2-binary   2.8.6
pyparsing         2.4.7
python-crfsuite   0.9.7
python-dateutil   2.8.1
pytz              2020.1
regex             2020.9.27
requests          2.24.0
setuptools        41.2.0
six               1.15.0
soupsieve         2.0.1
spacy             2.3.2
srsly             1.0.2
thinc             7.4.1
tqdm              4.50.1
urllib3           1.25.10
wasabi            0.8.0
webencodings      0.5.1
WARNING: You are using pip version 20.2.3; however, version 20.3.1 is available.
You should consider upgrading via the 'c:\python\myenv\scripts\python.exe -m pip install --upgrade pip' command.
(myenv) C:\python\django\project\apps>

By typing the command, it will all the available module in the current working python environment. By looking to the output, there is no module with the name of ‘django’. In order to solve this, just install the django module. The installation is in the following django module installation command :

(myenv) C:\python\django\project\apps>pip install django
Collecting django
  Downloading Django-3.1.4-py3-none-any.whl (7.8 MB)
     |████████████████████████████████| 7.8 MB 16 kB/s
Collecting sqlparse>=0.2.2
  Downloading sqlparse-0.4.1-py3-none-any.whl (42 kB)
     |████████████████████████████████| 42 kB 76 kB/s
Collecting asgiref<4,>=3.2.10
  Downloading asgiref-3.3.1-py3-none-any.whl (19 kB)
Requirement already satisfied: pytz in c:\python\myenv\lib\site-packages (from django) (2020.1)
Installing collected packages: sqlparse, asgiref, django
Successfully installed asgiref-3.3.1 django-3.1.4 sqlparse-0.4.1
WARNING: You are using pip version 20.2.3; however, version 20.3.1 is available.
You should consider upgrading via the 'c:\python\myenv\scripts\python.exe -m pip install --upgrade pip' command.
(myenv) C:\python\django\project\apps>

After successfully installing the ‘django’ module, just re-execute the above command for running the django-based web application as in the following command execution :

(myenv) C:\python\apps\apps>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
December 10, 2020 - 21:44:54
Django version 3.1.4, using settings 'apps.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

Leave a Reply