Mac + virtualenv + pip + postgresql = Error: pg_config executable not found Mac + virtualenv + pip + postgresql = Error: pg_config executable not found python python

Mac + virtualenv + pip + postgresql = Error: pg_config executable not found


On the Mac, if you're using Postgres.app, the pg_config file is in your /Applications/Postgres.app/Contents/Versions/<current_version>/bin directory. That'll need to be added to your system path to fix this error, like this:

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/<current_version>/bin

So for example, if the current Postgres.app version is 9.5, this export line would be:

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.5/bin

With more recent versions of the Postgres.app (> 9.5?), you can simply add "latest" in place of the version number, like so:

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin


On Mac, the solution is to install postgresql:

brew install postgresql

On CentOS, the solution is to install postgresql-devel:

sudo yum install postgresql-devel

pg_config is in postgresql-devel package


I totally agree with john hight that most of posted answers are totally offtopic assuming the OP exactly specified need of using virtualenv.

For me the answer was runing following command in prompt while having activated virtualenv:

export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"

(notice that part 9.4 stands for version and may vary)

or if you want to use the latest installed version of Postgres:

export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH" 

and then:

pip install psycopg2

goes sucesfully assuming you have installed postgres. And if not, then remember that the best and recomended solution is to use: Postgres.app