Error Code 1 when trying to "pip install psycopg2" in Max OSX Yosemite

10,884

Solution 1

If you run error like this then you need install two packages.

    sudo apt-get install libpq-dev python-dev

now install psycopg2

    pip install psycopg2

Solution 2

pg_config should located in

/Library/PostgreSQL/9.3/bin/pg_config

(substitute what ever version of Postgres you have installed for the 9.3)

Just add that directory to your PATH environment variable and you should be able to move forward.

Solution 3

If you have installed the Postgres.app, the one that sits in the Mac's menu bar, you will have to point your path at the pg_config executable in the App's bundle. You can navigate to the executable by visiting

/Applications/Postgres.app/Contents/Versions/9.3/bin

where your version would depend on what you have installed. Add this to to your $PATH variable in your .bash_profile, reload it, and voila!

Solution 4

Run this in your terminal to get the location of the pg_config executable

which pg_config

Depending on how you installed postgres, you should get a path similar to either of these

/Library/PostgreSQL/9.3/bin/pg_config

or

/usr/local/bin/pg_config

Add the directory holding the pg_config executable to your PATH environment variable like this

export PATH="/Library/PostgreSQL/9.3/bin:$PATH"

or

export PATH="/usr/local/bin:$PATH"

If the command which pg_config returns nothing, then you should install postgres first by running

brew install postgres

Then repeat the steps listed above.

Share:
10,884
Felix Dasgupta
Author by

Felix Dasgupta

Updated on June 22, 2022

Comments

  • Felix Dasgupta
    Felix Dasgupta almost 2 years

    I am trying to use postgresql in my Django project so I have been trying to install psycopg2 however I keep running into problems. Since I am using a virtualenv, installing psycopg2 through macports isn't helping. I need to find someway to install it as an app within my virtual env.

    Here is the error I get when I try to pip install it in my virtualenv:

    Downloading/unpacking psycopg2
    Downloading psycopg2-2.5.4.tar.gz (682kB): 682kB downloaded
    Running setup.py     (path:/Users/adfelix2/Documents/Hindsait_Work/Projects/nybc_pilot/build/psycopg2/setup.py) egg_info for package psycopg2
    
        Error: pg_config executable not found.
    
        Please add the directory containing pg_config to the PATH
        or specify the full executable path with the option:
    
        python setup.py build_ext --pg-config /path/to/pg_config build ...
    
        or with the pg_config option in 'setup.cfg'.
        Complete output from command python setup.py egg_info:
        running egg_info
    
    creating pip-egg-info/psycopg2.egg-info
    
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    
    warning: manifest_maker: standard file '-c' not found
    
    
    
    Error: pg_config executable not found.
    
    
    
    Please add the directory containing pg_config to the PATH
    
    or specify the full executable path with the option:
    
    
    
        python setup.py build_ext --pg-config /path/to/pg_config build ...
    
    
    
    or with the pg_config option in 'setup.cfg'.
    
    ----------------------------------------
    Cleaning up...
    Command python setup.py egg_info failed with error code 1 in         /Users/user/'privateinfo'/my_virtualenv/build/psycopg2
    Storing debug log for failure in /Users/user/.pip/pip.log
    

    Seems like I need to add a directory to pg_config? However I am unable to come across anything online that would help me do so. If anybody has an answer to this, in a step-by-step manner, it would be very gladly appreciated. Thank you.