3

I'm creating a startproject and I'm trying to migrate default django schema using the command line:

manage.py migrate

The result is: "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?"

I'm using a virtual environment and I have the next dependencies installed:

Django==2.1.2
psycopg2==2.7.5
pytz==2018.5 

Of course, I'm trying to migrate with the virtual environment activated.

Somebody knows if I've got a problem with the compatibility of the versions? My PostgreSQL is 10.

pip list command

piro
  • 13,378
  • 5
  • 34
  • 38
Claudio Roldán
  • 31
  • 1
  • 1
  • 4

1 Answers1

3

This most likely means that you're not running the command from within the activated virtualenv:

C:\> my_venv\Scripts\activate

(my_venv) C:\>  (type your command now)

The error message you're getting is produced if unable to import django.core.management:

try:
    from django.core.management import execute_from_command_line
except ImportError as exc:
    raise 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?"
    ) from exc

You can get into the Python console with the same environment as the faulty command (e.g. in your case, type python in the same console window) and try to import that module by hand, then diagnose the resulting import error.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
  • Thanks for your answer, it works. I ran manage.py runserver in Windows command prompt and it didn't work but it worked once I typed the same command in the Anaconda prompt. So, can I think that Anaconda prompt is a kind of activated virtualenv? – Json Feb 24 '19 at 09:58
  • @Jason Anaconda's prompt activates the `base` Anaconda environment when it's started. Strictly speaking, an Anaconda environment is not a virtualenv (it's not based on the `virtualenv` module but rather uses Anaconda's custom logic), but it works the same way so it can be considered a flavor of virtualenv. – ivan_pozdeev Feb 24 '19 at 19:42