I've initialised a virtual environment using the virtualenvwrapper command mkvirtualenv -a <path to project> django_project
.
I then installed django with pip install django
. But then if i try to use django-admin
i get:
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 7, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
Now pip list
gives me
Package Version
---------- -------
Django 2.1.3
pip 18.1
pytz 2018.7
setuptools 40.6.2
wheel 0.32.3
python -m django --version
gives
2.1.3
If I run which python
it correctly points to my virtualenv, however which django-admin
gives:
/usr/local/bin/django-admin
I'd think that it should point to my venv. Why would it point to a global django admin? How do I fix it so that it'll work for my future virtual environments?
I'm on MacOS using zsh and python 3.7.0.
Thank you!
Edit: Mistake in a command
Edit: I realised I don't have a system-wide installation of Django and so the django-admin
and django-admin.py
files in my /usr/local/bin
must've been leftovers from an earlier installation. Hence I deleted them and that solved the problem. Without any further django-admin
inside the venv point to the correct django installation (inside the venv).
However, I would still like to know why the command didn't point to the Django installed in the venv in the first place?
So Django has been installed at system level, while you verified that python
command refer to your virtual environment. I bet this is an issue with pip
. You may check that it is under <path to project>/bin
and is correctly used when you perform
(django_project) $ pip install django
Try to run
which pip
with your venv enabled and disabled to see what pip is used in each case
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With