In this Python Django Tutorial, I will show you how to solve the ModuleNotFoundError: no module named Django, which is most common error that occurs when you are working with Django.
In this tutorial, you will understand reason behind that error and how to resolve that error. Addtionally I will show you how to solve the error ModuleNotFoundError: no module named Django on different operating systems.
ModuleNotFoundError: No module named Django
If you see the error ‘ModuleNotFoundError: No module named Django’ which means when you run the django command, it doesn’t find the Django module.
So whaterver command you run that are related to the Django, all the command exist in the module Django. There are most common reason to get that error:
- First check the Python interpreter, may be you are using the wrong Python interpreter. In other words, may be you have installed the multiple version of the Python and you install the Django for specific version of Python.
- And when you run the command from the different version of Python interpreter, then you get that kind of error.
- The second reason can be the virtual environment, sometime you forget to install the Django in virtual environment so make sure you install the Django in your activated virtual envrionment using ‘pip install django’ in your terminal.
- The third resaon can be installation of Djang package globally and not in virtual environment
There are can many more reasons like you are working on Django project and after some updates, you start get that error.
To resolve this issue, you can follow the following solution which is based on different operating systems.
No module named Django windows 10
In this section, we will learn how to solve the modulenotfounderror: no module named ‘django’ in windows 10.
For this, firstly check whether you have pip installed or not, by simply writing the command pip in the python terminal. If you have then it’s fine, otherwise, from the internet download a python script called get-pip.py and save it to your local system.
Command:
# Check pip is installed or not
pip
Pip is the package insatller used to install packages from the Python Packages.
Try to be aware of location the file was saved and change the current directory from the command prompt to that location.
#If pip is not installed then
cd path_of_dir_of_get-pip_script
After this, install pip and run the get-pip.py script by writing the following command:
"python .\get-pip.py"
Now, to install Django with its dependencies type the following command:
pip install django
Your, error will be resolved. Or, if not resolved then check the following steps.
- If you installed Django in a virtual environment, make sure it must be activated.
source venv/bin/activate
- Make sure the Django version you’re installing is compatible with the Python version you have installed.
- If you have a 64-bit version of Python installed, ensure sure Django is 64-bit as well. In the case of 32 bits, both must be 32 bits.
- Make sure to include the path to Python in the PATH variable for system and environment variables.
- Upgrade pip to the most recent version if it is out of date.
python -m pip install --upgrage pip
- Make sure there are no errors in the import statement as well.
Read: Python Change Django Version
No module named Django ubuntu
In this section, we’ll learn to resolve the modulenotfounderror: no module named ‘django’ in Ubuntu.
To resolve this error, you have to install Django. So, to install Django, firstly, update your locale package with apt:
sudo apt update
Next, check which version of Python you have installed. And make sure it should be compatible with both Ubuntu and Django.
python3 -V
And, in last install the Django through the APT package manager.
sudo apt install python3-django
If you want to install Django with pip, follow the command:
sudo pip install django
With the above steps, your error will be resolved.
Also, check: Python Django vs Pyramid
No module named Django macOS
In this section, we’ll learn to resolve the modulenotfounderror: no module named ‘django’ in macOS.
To resolve this error, you have to install Django. And, before installing Django must check Python is installed or not. If already installed install pip package, and if not installed install python first and then pip package also.
And, after this finally, install Django.
sudo pip install django
With the above steps, your error will be resolved.
Conclusion
In this Python Django Tutorial, you learned how to solve the ModuleNotFoundError: no module named Django, and learned about different reason that can raise this kind of error. Also you learned how to fix this error on different operating systems.
You may also like to read the following Django tutorials.
- Get URL parameters in Django
- If statement in Django template
- Django get all data from POST request
- Convert HTML page to PDF using Django
- AttributeError module object has no attribute in Django
- Python Django where to save base template for all apps
I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.