Search code examples
pythondjangopycharmcookiecutter-django

Can't Run Django Manage.py from Venv


I'm trying to run manage.py makemigrations for my django app, and I'm getting a "Couldn't import Django" message.

I know how venv works and I'm sure my environment includes Django. See below; I try to run manage.py (running into the error), and then I run $ django-admin --version, and it shows the version of Django.

    (venv) emmett@emmett-HP:~/PycharmProjects/onramp_crm$ sudo python manage.py makemigrations contacts
Traceback (most recent call last):
  File "manage.py", line 18, in <module>
    "Couldn't import Django. Are you sure it's installed and "
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?
(venv) emmett@emmett-HP:~/PycharmProjects/onramp_crm$ django-admin --version
2.0.9
(venv) emmett@emmett-HP:~/PycharmProjects/onramp_crm$ 

This is a django-cookiecutter project using Pycharm Pro edition. I've deleted the onramp_crm/venv folder and completely reinstalled the venv, setting up a new interpreter in Pycharm as well. Logged out & restarted Ubuntu, restarted Pycharm, everything I can think of.


Solution

  • Remove the sudo from sudo python manage.py makemigrations contacts.

    Using sudo will use your system version of Python, which, it seems, does not have Django installed. Without sudo you'll use the venv, which has Django.