I’m trying make online a project but there is an error i can’t solve myself.
I already installed django but the server give me this error.
Virtualenv is also active.
2017-09-25 20:10:27,471: ***************************************************
2017-09-25 20:10:30,892: Error running WSGI application
2017-09-25 20:10:30,893: ModuleNotFoundError: No module named 'django'
2017-09-25 20:10:30,893:   File "/var/www/asd1_pythonanywhere_com_wsgi.py", line 17, in <module>
2017-09-25 20:10:30,893:     from django.core.wsgi import get_wsgi_application
2017-09-25 20:10:30,893: ***************************************************
2017-09-25 20:10:30,893: If you're seeing an import error and don't know why,
2017-09-25 20:10:30,894: we have a dedicated help page to help you debug: 
2017-09-25 20:10:30,894: https://help.pythonanywhere.com/pages/DebuggingImportError/
2017-09-25 20:10:30,894: ***************************************************
Wsgi file is it:
    import os
import sys
path = '/home/asd1/mysite'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Hosting is pythonanywhere.com
asked Sep 25, 2017 at 20:29
3
You need to install Django. You may have forgotten to install it while the environment was active.
You can learn how to do this here.
This also could be because you have called your project a name such as «django» which would conflict with the installed packages.
answered Sep 25, 2017 at 20:33
montudormontudor
5024 silver badges10 bronze badges
4
The error means Django is not installed. You can install Django with the following command
python -m pip install Django
answered Jan 25, 2021 at 11:45
trustidkidtrustidkid
5674 silver badges6 bronze badges
Did you follow the instruction on how to edit your wsgi? From the help page:
Edit your WSGI file
One thing that’s important here: your Django project (if you’re using a recent version of Django) will have a file inside it called wsgi.py. This is not the one you need to change to set things up on PythonAnywhere — the system here ignores that file.
Instead, the WSGI file to change is the one that has a link inside the «Code» section of the Web tab — it will have a name something like /var/www/yourusername_pythonanywhere_com_wsgi.py or /var/www/www_yourdomain_com_wsgi.py.
answered Sep 25, 2017 at 20:40
MaelstromMaelstrom
4432 silver badges9 bronze badges
1
This might be answered many times, but recently I upgraded my ubuntu 18.04 to 19.10, and without changing any other thing, my running django server stopped running with this error: ModuleNotFoundError: No module named 'django'. I repeated the same install, python3 -m pip install django and it didn’t help. Finally somebody else told me to use
sudo python3 -m pip install django 
because I run the server with sudo python3 manage.py runserver 0.0.0.0:80, which actually worked for me. 
answered Feb 26, 2020 at 19:10
JCQianJCQian
8096 silver badges10 bronze badges
1

                
Every django developer has experience of facing this issue. It is one of the most common errors you will face when running your first migration. This error can also produce other errors such as «TemplateDoesNotExist«.
In this article we will see two most common reasons that cause Django Import Error: No module named
  1. Forgot to put app name to installed_apps list?
The most common mistake that beginners make is that they forget to list their apps in INSTALLED_APPS which is present in the settings.py file.
Therefore, please make sure that your app is listed in the INSTALLED_APPS. Example:
Suppose, I have a newly started app called users within a project named polls project then I would navigate to pollsproject/settings.py and will search for INSTALLED_APPS and will append ‘users‘ or  ‘users.apps.UsersConfig‘ to it.
INSTALLED_APPS = [
   'users.apps.UsersConfig', # added users app here
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
]
Enter fullscreen mode
Exit fullscreen mode
This is the most common solution for TemplateDoesNotExist error as well so make sure you have not committed this mistake.
Now, let’s look at another most common mistake that a beginner makes which results in this error.
  2. App is not in the root directory of your project.
If you have listed your apps inside INSTALLED_APPS but still you are facing the *Django Import Error: No module named * error then it might be due to django could not find your app within the root directory.
Your apps can be place anywhere, but Django by default starts to search app from the project’s root directory and if it does not find the app there then it will throw the same ImportError error.
Therefore, please make sure that your app is located in the same directory where manage.py file is located. For example, for a random project named pollsproject, I have created an app called users, then the whole tree structure of my project would look like:
polls-project/
├── env/
├── pollsproject/
│   ├── pollsproject/
│   │   ├── __init__.py
│   │   ├── asgi.py
│   │   ├── settings.py
│   │   ├── urls.py
│   │   └── wsgi.py
│   ├── users/
│   │   ├── migrations/
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── models.py
│   │   ├── tests.py
│   │   └── views.py
│   ├── db.sqlite3
│   └── manage.py
├── .gitignore
├── requirements.txt
Enter fullscreen mode
Exit fullscreen mode
The main cause of this problem is that when you start a fresh project and then you start an app using the django-admin command from the same location from where you run the startproject command. This will create an app outside the project’s root directory. Therefore, to avoid this issue use python manage.py startapp instead of «django-admin startapp or make sure you’re in the same directory as manage.py
The good news is that Django’s apps are «Pluggable» therefore, you can just move your app to the directory same as manage.py and it should work.
Let me know if none of these two worked for you, I will be more than glad to help you.
Happy Coding 🧡
In this Python Django Tutorial, we will discuss how to solve the ModuleNotFoundError: no module named Django, and we shall also cover the following topics:
- No module named Django windows 10
 - No module named Django ubuntu
 - No module named Django macOS
 
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
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.
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
 
In this Python Django Tutorial, we have discussed the Python Django no module Django and we have also covered the following topics:
- No module named Django windows 10
 - No module named Django ubuntu
 - No module named Django macOS
 
Python is one of the most popular languages in the United States of America. I have been working with Python for a long time and I have expertise in working with various libraries on Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… I have experience in working with various clients in countries like United States, Canada, United Kingdom, Australia, New Zealand, etc. Check out my profile.
A common error you may encounter when using Python is modulenotfounderror: no module named ‘django’.
This error occurs when the Python interpreter cannot detect the Django library in your current environment.
You can install Django in Python 3 with python -m pip install django.
This tutorial goes through the exact steps to troubleshoot this error for the Windows, Mac and Linux operating systems.
Table of contents
- ModuleNotFoundError: no module named ‘django’
- What is ModuleNotFoundError?
 - What is Django?
 
 - Always Use a Virtual Environment to Install Packages
- How to Install Django on Windows Operating System
- Django installation on Windows Using pip
 
 - How to Install Django on Mac Operating System using pip
 - How to Install Django on Linux Operating Systems
- Installing pip for Ubuntu, Debian, and Linux Mint
 - Installing pip for CentOS 8 (and newer), Fedora, and Red Hat
 - Installing pip for CentOS 6 and 7, and older versions of Red Hat
 - Installing pip for Arch Linux and Manjaro
 - Installing pip for OpenSUSE
 - Django installation on Linux with Pip
 
 
 - How to Install Django on Windows Operating System
 - Installing Django Using Anaconda
- Check Django Version
 
 - Summary
 
ModuleNotFoundError: no module named ‘django’
What is ModuleNotFoundError?
The ModuleNotFoundError occurs when the module you want to use is not present in your Python environment. There are several causes of the modulenotfounderror:
The module’s name is incorrect, in which case you have to check the name of the module you tried to import. Let’s try to import the re module with a double e to see what happens:
import ree
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
1 import ree
ModuleNotFoundError: No module named 'ree'
To solve this error, ensure the module name is correct. Let’s look at the revised code:
import re
print(re.__version__)
2.2.1
You may want to import a local module file, but the module is not in the same directory. Let’s look at an example package with a script and a local module to import. Let’s look at the following steps to perform from your terminal:
mkdir example_package
cd example_package
mkdir folder_1
cd folder_1
vi module.py
Note that we use Vim to create the module.py file in this example. You can use your preferred file editor, such as Emacs or Atom. In module.py, we will import the re module and define a simple function that prints the re version:
import re
def print_re_version():
    print(re.__version__)
Close the module.py, then complete the following commands from your terminal:
cd ../
vi script.py
Inside script.py, we will try to import the module we created.
import module
if __name__ == '__main__':
    mod.print_re_version()
Let’s run python script.py from the terminal to see what happens:
Traceback (most recent call last):
  File "script.py", line 1, in ≺module≻
    import module
ModuleNotFoundError: No module named 'module'
To solve this error, we need to point to the correct path to module.py, which is inside folder_1. Let’s look at the revised code:
import folder_1.module as mod
if __name__ == '__main__':
    mod.print_re_version()
When we run python script.py, we will get the following result:
2.2.1
Lastly, you can encounter the modulenotfounderror when you import a module that is not installed in your Python environment.
What is Django?
Django is a high-level framework for building web applications hat encourages rapid development and clean, pragmatic design.
The simplest way to install Django is to use the package manager for Python called pip. The following installation instructions are for the major Python version 3.
Always Use a Virtual Environment to Install Packages
It is always best to install new libraries within a virtual environment. You should not install anything into your global Python interpreter when you develop locally. You may introduce incompatibilities between packages, or you may break your system if you install an incompatible version of a library that your operating system needs. Using a virtual environment helps compartmentalize your projects and their dependencies. Each project will have its environment with everything the code needs to run. Most ImportErrors and ModuleNotFoundErrors occur due to installing a library for one interpreter and using the library with another interpreter. Using a virtual environment avoids this. In Python, you can use virtual environments and conda environments. We will go through how to install Django with both.
How to Install Django on Windows Operating System
First, you need to download and install Python on your PC. Ensure you select the install launcher for all users and Add Python to PATH checkboxes. The latter ensures the interpreter is in the execution path. Pip is automatically on Windows for Python versions 2.7.9+ and 3.4+.
You can check your Python version with the following command:
python3 --version
You can install pip on Windows by downloading the installation package, opening the command line and launching the installer. You can install pip via the CMD prompt by running the following command.
python get-pip.py
You may need to run the command prompt as administrator. Check whether the installation has been successful by typing.
pip --version
Django installation on Windows Using pip
To install Django, first, create the virtual environment. The environment can be any name, in this we choose “env”:
virtualenv env
You can activate the environment by typing the command:
envScriptsactivate
You will see “env” in parenthesis next to the command line prompt. You can install Django within the environment by running the following command from the command prompt.
python3 -m pip install django
We use python -m pip to execute pip using the Python interpreter we specify as Python. Doing this helps avoid ImportError when we try to use a package installed with one version of Python interpreter with a different version. You can use the command which python to determine which Python interpreter you are using.
How to Install Django on Mac Operating System using pip
Open a terminal by pressing command (⌘) + Space Bar to open the Spotlight search. Type in terminal and press enter. To get pip, first ensure you have installed Python3:
python3 --version
Python 3.8.8
Download pip by running the following curl command:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
The curl command allows you to specify a direct download link. Using the -o option sets the name of the downloaded file.
Install pip by running:
python3 get-pip.py
To install Django, first create the virtual environment:
python3 -m venv env
Then activate the environment using:
source env/bin/activate 
You will see “env” in parenthesis next to the command line prompt. You can install Django within the environment by running the following command from the command prompt.
python3 -m pip install django
How to Install Django on Linux Operating Systems
All major Linux distributions have Python installed by default. However, you will need to install pip. You can install pip from the terminal, but the installation instructions depend on the Linux distribution you are using. You will need root privileges to install pip. Open a terminal and use the commands relevant to your Linux distribution to install pip.
Installing pip for Ubuntu, Debian, and Linux Mint
sudo apt install python-pip3
Installing pip for CentOS 8 (and newer), Fedora, and Red Hat
sudo dnf install python-pip3
Installing pip for CentOS 6 and 7, and older versions of Red Hat
sudo yum install epel-release
sudo yum install python-pip3
Installing pip for Arch Linux and Manjaro
sudo pacman -S python-pip
Installing pip for OpenSUSE
sudo zypper python3-pip
Django installation on Linux with Pip
To install Django, first create the virtual environment:
python3 -m venv env
Then activate the environment using:
source env/bin/activate 
You will see “env” in parenthesis next to the command line prompt. You can install Django within the environment by running the following command from the command prompt.
Once you have activated your virtual environment, you can install Django using:
python3 -m pip install django
Installing Django Using Anaconda
Anaconda is a distribution of Python and R for scientific computing and data science. You can install Anaconda by going to the installation instructions. Once you have installed Anaconda, you can create a virtual environment and install Django.
To create a conda environment, you can use the following command:
conda create -n django-project python=3.8
You can specify a different Python 3 version if you like. Ideally, choose the latest version of Python. Next, you will activate the project container. You will see “django-project” in parentheses next to the command line prompt.
source activate django-project
Now you’re ready to install Django using conda.
Once you have activated your conda environment, you can install Django using the following command:
conda install -c conda-forge django
Check Django Version
Once you have successfully installed Django, you can check its version. If you used pip to install Django, you can use pip show from your terminal.
python3 -m pip show django
Name: Django
Version: 4.0.2
Summary: A high-level Python web framework that encourages rapid development and clean, pragmatic design.
Second, within your python program, you can import the Django and then reference the __version__ attribute:
import django
print(django.__version__)
4.0.2
If you used conda to install Django, you could check the version using the following command:
conda list -f django
# Name                    Version                   Build  Channel
django                    4.0.2            py38h50d1736_0    conda-forge
Summary
Congratulations on reading to the end of this tutorial. The modulenotfounderror occurs if you misspell the module name, incorrectly point to the module path or do not have the module installed in your Python environment. If you do not have the module installed in your Python environment, you can use pip to install the package. However, you must ensure you have pip installed on your system. You can also install Anaconda on your system and use the conda install command to install Django.
Go to the online courses page on Python to learn more about Python for data science and machine learning.
For further reading on missing modules in Python, go to the article:
- How to Solve Python ModuleNotFoundError: no module named ‘environ’
 
Have fun and happy researching!
| Python не находит Django | |
| Disallowed host | |
| Не работает runserver | |
| Web application could not be started | |
| 
 You have X unapplied migrations  | 
|
| 
 ERROR: Can not perform a ‘—user’ install  | 
Python не находит Django
(docker) andreyolegovich.ru@server:~/HelloDjango [0] $ python3 manage.py runserver
Traceback (most recent call last):
  File «manage.py», line 8, in <module>
    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 14, in <module>
    ) 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?
    Причина в том, что в PATH не прописан путь до python. Вернитесь к шагу
    PATH
Disallowed host
Вы можете запустить Django с помощью
python3 manage.py runserver
    И прописали в
    
        settings.py
    
    свои хосты, например так
ALLOWED_HOSTS = ['http://www.andreyolegovich.ru','127.0.0.1','localhost','andreyolegovich.ru','www.andreyolegovich.ru']
    
Но при обращении к домену в браузере появляется ошибка DisallowedHost
DisallowedHost at /
Invalid HTTP_HOST header: ‘www.andreyolegovich.ru’. You may need to add ‘www.andreyolegovich.ru’ to ALLOWED_HOSTS.
Request Method:	GET
Request URL:	http://www.andreyolegovich.ru/
Django Version:	2.1.5
Exception Type:	DisallowedHost
Exception Value:
Invalid HTTP_HOST header: ‘www.andreyolegovich.ru’. You may need to add ‘www.andreyolegovich.ru’ to ALLOWED_HOSTS.
Exception Location:	/home/a/andreyolegovichru/.local/lib/python3.7/site-packages/django/http/request.py in get_host, line 106
Python Executable:	/home/a/andreyolegovichru/.local/bin/python3.7
Python Version:	3.7.0
Python Path:
[‘/home/a/andreyolegovichru/andreyolegovich.ru/public_html/HelloDjango’,
 ‘/home/a/andreyolegovichru/.local/lib/python3.7/site-packages’,
 ‘/home/a/andreyolegovichru/andreyolegovich.ru’,
 ‘/opt/passenger40/helper-scripts’,
 ‘/home/a/andreyolegovichru/.local/lib/python37.zip’,
 ‘/home/a/andreyolegovichru/.local/lib/python3.7’,
 ‘/home/a/andreyolegovichru/.local/lib/python3.7/lib-dynload’,
 ‘/home/a/andreyolegovichru/.local/lib/python3.7/site-packages’]
Server time:	Sun, 3 Feb 2019 20:07:57 +0000
    Проверьте, всё ли правильно прописали в
    
        settings.py
    
    ALLOWED_HOSTS.
    
Выключите Django, закройте все консоли подключенные к хостингу или все консоли на локальной машине.
Очистите кэш браузера или откройте url другим браузером.
Не работает runserver Django
Если Вы выполняете команду
python3 manage.py runserver
    И ничего не происходит, или например, у Вас работал самый первый проект, а запустить
    второй не получается — скорее всего дело в хостинге. На нём может быть закрыта
    возможность слушать порты и выбор рабочего проекта происходит с помощью
    какого-то скрипта.
    
    Если Вы, как и я, пользуетесь
    хостингом beget
    , тот этот скипт будет называться
    
        passenger_wsgi.py
    
    и лежать будет на одном уровне с директорией public_html.
    
Пропишите в нём
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘Название_нового_прокта.settings’
Web application could not be started
    Если Вы хотите переключиться между проектами и уже обновили скрипе passenger_wsgi.py
    но получили ошибку
Web application could not be started
Скорее всего Вы забыли пересоздать файл tmp/restart.txt
(docker) andreyolegovich@server:~/andreyolegovich.ru [0] $ touch tmp/restart.txt
Также советую перепроверить не забыли ли Вы поменть системный путь на нужный Вам проект.
При смене проекта обычно нужно делать два изменения в файле passenger_wsgi.py
# -*- coding: utf-8 -*-
import os, sys
sys.path.insert(0, ‘/home/a/andreyolegovich/andreyolegovich.ru/public_html/Project_1’)
#sys.path.insert(0, ‘/home/a/andreyolegovich/andreyolegovich.ru/public_html/Project_2’)
sys.path.insert(1, ‘/home/a/andreyolegovich/.local/lib/python3.7/site-packages’)
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘Project_1.settings’
#os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘Project_2.settings’
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
    Ещё одна возможная причина — незаданные переменные в файле
    
        manage.py
    
    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.
python3 manage.py migrate
ERROR: Can not perform a ‘—user’ install. User site-packages are not visible in this virtualenv.
Если вы пользуетесь виртуальным окружением флаг —user вам скорее всего вообще не нужен.
You must have used Django Framework for the machine learning dashboard.The python module djangorestframework allows you to build RESTful web applications. But if you are getting the error modulenotfounderror: no module named rest_framework then this post is for you. You will learn why you are getting this error and how you can solve it.
What is ModuleNotFoundError ?
Most of case the programmer or developer get this ModuleNotFoundError when they try to import a module and the python interpreter unable to find it. For example, if you try to import the module “X” and if it is not installed in your system then you will get the error “ModuleNotFoundError: no module named “X”.
Why does the modulenotfounderror: no module named rest_framework occur?
The main or root cause for this error is that the python interpreter is unable to find the djangorestframework module in your system. You will get the error when you import this rest_framework.
import rest_framework
Output
Solve the no module named rest_framework Error
Solution 1:
The solution to this no module named error is very simple. You have to just install the djangorestframework using the pip command. You have to first verify the version of python. If your python version is 3. xx then use the pip3 command and if it is 2. xx then use the pip command.
For python 3.xx
pip3 install djangorestframework
For python 2.xx
pip install djangorestframework
Now you will not get the error when you import this module.
For conda
conda install djangorestframework
Solution 2:
But if you are still getting this error then you have to set the python path. Open your terminal and type the below command.
export PYTHONPATH=~/rest_framework
Solution 3:
If you’re still getting the “ModuleNotFoundError” error then it’s possible that the djangorestframework module is installed. But Django is unable to find it. For this case add the module to your Django settings:
INSTALLED_APPS = [ ... 'rest_framework', ]
After making the changes you have to restart your Django application. After restarting, you may not get the “ModuleNotFoundError”.
Conclusion
Django Rest Framework is a plugin for the Django that allows you to build web APIs. If you are getting the error modulenotfounderror: no module named rest_framework then the above solution will solve it.
I hope you have liked this tutorial. If your problem has not still solved then you can contact us for more help.
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
We respect your privacy and take protecting it seriously
Thank you for signup. A Confirmation Email has been sent to your Email Address.
Something went wrong.


