Skip to content
Advertisement

ModuleNotFoundError: No module named ‘django.core’

I want to create django project so I’ve configured virtualenv ,and I installed django pipenv install django==4.0.1 when I create app using this command python3 manage.py startapp Accounts I got this error.

(env) zakaria@ZAKARIA:/mnt/c/Users/ZAKARIA/Desktop/project$ python manage.py startapp Accounts
Traceback (most recent call last):
  File "manage.py", line 11, in main
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django.core'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 13, 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?

can any one help to solve this problem ?

Advertisement

Answer

Instead of python3 manage.py startapp Accounts try python manage.py startapp Accounts with your venv activated.

To explain why this matters, let’s go through an exercise. Starting without a venv activated, try this process (you may need to use the deactivate command to turn off if you’re in a venv:

python -m venv my_venv
# The following line assumes you're on Linux or Mac; it appears you're using WSL-2, which is fine
. my_venv/bin/activate
# The following command should show the path to the Python binary in your venv
which python
# The following command may show that you're not hitting the Python version in your venv, but somewhere else
which python3

You want to make sure you’re using the Python binary that is inside your venv. Good luck!

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement