Mac + virtualenv + pip + postgresql = Error: pg_co

2019-01-12 21:29发布

I was trying to install postgres for a tutorial, but pip gives me error:

pip install psycopg

A snip of error I get:

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'.

Where is pg_config in my virtualenv? How to configure it? I'm using virtualenv because I do not want a system-wide installation of postgres.

14条回答
ゆ 、 Hurt°
2楼-- · 2019-01-12 22:27

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
查看更多
爷的心禁止访问
3楼-- · 2019-01-12 22:27

If you're using postgresql 9.4, the file is located in

/usr/pgsql-9.4/bin/pg_config

The name of the package is

postgresql94-9.4.9-1PGDG.rhel6.x86_64

to add pg_config to your PATH, do the following

PATH=$PATH:/usr/pgsql-9.4/bin/
查看更多
登录 后发表回答