ModuleNotFoundError: No module named django

Published On: 21/07/2022 | Category: Django Python

Hi Dev,

Now, let's see post of modulenotfounderror: no module named 'django'. I explained simply about modulenotfounderror no module named django ubuntu. This tutorial will give you simple example of modulenotfounderror: no module named django. In this article, we will implement a no module named django but it is installed.

So, sometimes if you got the error “ModuleNotFoundError: No module named ‘django'” it means that Python couldn’t find your Django package. Here’s the full error message:

Here, below describe the simple solution...

Traceback (most recent call last):
  File "", line 10, in main
    from 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 "", line 21, in 
  File "", line 16, 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 virtual environment?

First of all need to check installed or not if you know that Django was installed, here are some quick things to check:

Here, If you installed it in a virtual environment, make sure that you activate your virtual environment:

$ source venv/bin/activate

Next, we can check which paths python looks in for the django module you can run this code:

(venv) $ python
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/usr/lib/', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/opt/code/venv/lib/python3.6/site-packages']

If Django is not located in one of those paths, it means that you didn’t install Django or didn’t install it in the right location.

Then install Django with this command:

(venv) $ pip install django

I Hope It will help you....