You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application

后端 未结 9 999
半阙折子戏
半阙折子戏 2020-12-22 17:10

I am working on Django project with virtualenv and connect it to local postgres database. when i run the project is says,

ImportError: No module named psycop         


        
相关标签:
9条回答
  • 2020-12-22 17:40

    For me this simple command solved the problem:

    sudo apt-get install postgresql postgresql-contrib libpq-dev python-dev
    

    Then I can do:

     pip install psycopg2
    
    0 讨论(0)
  • 2020-12-22 17:45

    Run the command below;

    sudo apt-get install python-pip python-dev libpq-dev postgresql postgresql-contrib
    pip install psycopg2
    
    0 讨论(0)
  • 2020-12-22 17:48

    I just run this command as a root from terminal and problem is solved,

    sudo apt-get install -y postgis postgresql-9.3-postgis-2.1
    pip install psycopg2
    

    or

    sudo apt-get install libpq-dev python-dev
    pip install psycopg2
    
    0 讨论(0)
  • 2020-12-22 17:56

    Use these following commands, this will solve the error:

    sudo apt-get install postgresql
    

    then fire:

    sudo apt-get install python-psycopg2
    

    and last:

    sudo apt-get install libpq-dev
    
    0 讨论(0)
  • 2020-12-22 17:59

    For Python 3, I did:

    sudo apt install python3-dev postgresql postgresql-contrib python3-psycopg2 libpq-dev
    

    and then I was able to do:

    pip3 install psycopg2
    
    0 讨论(0)
  • 2020-12-22 18:01

    I was using a virtual environment on Ubuntu 18.04, and since I only wanted to install it as a client, I only had to do:

    sudo apt install libpq-dev
    pip install psycopg2
    

    And installed without problems. Of course, you can use the binary as other answers said, but I preferred this solution since it was stated in a requirements.txt file.

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