pg_config executable not found

后端 未结 30 2151
渐次进展
渐次进展 2020-11-22 15:42

I am having trouble installing psycopg2. I get the following error when I try to pip install psycopg2:

Error: pg_config executable not found.

P         


        
相关标签:
30条回答
  • 2020-11-22 16:07

    UPDATE /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
    ADD exclude=postgresql*

    curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr  
    rpm -ivh pgdg-centos91-9.1-4.noarch.rpm
    
    yum install postgresql  
    yum install postgresql-devel
    
    PATH=$PATH:/usr/pgsql-9.1/bin/
    
    pip install psycopg2
    
    0 讨论(0)
  • 2020-11-22 16:07

    This was partly suggested before, adding it here for clarity.

    From the documentation at https://www.psycopg.org/docs/install.html.
    they suggest running: $ pip install psycopg2-binary

    That solved the issue for me.

    0 讨论(0)
  • 2020-11-22 16:08

    This is what worked for me on CentOS, first install:

    sudo yum install postgresql postgresql-devel python-devel
    

    On Ubuntu just use the equivilent apt-get packages.

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

    And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:

    sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2
    

    Make sure to include the correct path. Thats all :)

    0 讨论(0)
  • 2020-11-22 16:08

    Installing python-psycopg2 solved it for me on Arch Linux:

    pacman -S python-psycopg2
    
    0 讨论(0)
  • 2020-11-22 16:10

    Just to sum up, I also faced exactly same problem. After reading a lot of stackoverflow posts and online blogs, the final solution which worked for me is this:

    1) PostgreSQL(development or any stable version) should be installed before installing psycopg2.

    2) The pg_config file (this file normally resides in the bin folder of the PostgreSQL installation folder) PATH had to be explicitly setup before installing psycopg2. In my case, the installation PATH for PostgreSQL is:

    /opt/local/lib/postgresql91/
    

    so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal:

    PATH=$PATH:/opt/local/lib/postgresql91/bin/
    

    This command ensures that when you try to pip install psycopg2, it would find the PATH to pg_config automatically this time.

    I have also posted a full error with trace and its solution on my blog which you may want to refer. Its for Mac OS X but the pg_config PATH problem is generic and applicable to Linux also.

    0 讨论(0)
  • 2020-11-22 16:11

    sudo apt-get install libpq-dev works for me on Ubuntu 15.4

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