trouble with python manage.py migrate -> No module named psycopg2

前端 未结 3 859
慢半拍i
慢半拍i 2021-01-19 06:25

I am having some trouble with migrating Django using postgresql.

This is my first time with Django, and I am just following the tutorial.

As suggested on the

相关标签:
3条回答
  • 2021-01-19 06:55

    It's because you use Django in a python virtualenv and as stated on virtualenv web site :

    It creates an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments (and optionally doesn’t access the globally installed libraries either).

    That means that you need to install psycopg2 in your virtualenv and not globaly or make it access globaly installed libraries.

    0 讨论(0)
  • 2021-01-19 07:10

    It must be because you are installing psycopg2 in your system level python installation not in your virtualenv.

    sudo apt-get install python-psycopg2
    

    will install it in your system level python installation.

    You can install it in your virtualenv by

    pip install psycopg2
    

    after activating your virtualenv or you can create your virtualenv with --system-site-packages flag so that your virtualenv will have packages in your system level python already available.

    virtualenv --system-site-packages test
    

    where test is your virtualenv.

    0 讨论(0)
  • 2021-01-19 07:10

    Psycopg is the most popular PostgreSQL database adapter for the Python programming language. I was also facing a similar problem when I tried to run the migration with Postgresql database. The below step worked for me fine.

    Activate your Virtual Environment and run the following command

    pip install psycopg2-binary
    

    Now try running python manage.py migrate

    0 讨论(0)
提交回复
热议问题