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.
JavaScript
x
15
15
1
(env) zakaria@ZAKARIA:/mnt/c/Users/ZAKARIA/Desktop/project$ python manage.py startapp Accounts
2
Traceback (most recent call last):
3
File "manage.py", line 11, in main
4
from django.core.management import execute_from_command_line
5
ModuleNotFoundError: No module named 'django.core'
6
7
The above exception was the direct cause of the following exception:
8
9
Traceback (most recent call last):
10
File "manage.py", line 22, in <module>
11
main()
12
File "manage.py", line 13, in main
13
raise ImportError(
14
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?
15
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
:
JavaScript
1
8
1
python -m venv my_venv
2
# The following line assumes you're on Linux or Mac; it appears you're using WSL-2, which is fine
3
. my_venv/bin/activate
4
# The following command should show the path to the Python binary in your venv
5
which python
6
# The following command may show that you're not hitting the Python version in your venv, but somewhere else
7
which python3
8
You want to make sure you’re using the Python binary that is inside your venv
. Good luck!