我在安装psycopg2时遇到了麻烦。当我尝试pip安装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'.

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/psycopg2

但问题是pg_config实际上在我的PATH中;它运行起来没有任何问题:

$ which pg_config
/usr/pgsql-9.1/bin/pg_config

我尝试将pg_config路径添加到setup.cfg文件中,并使用我从他们的网站(http://initd.org/psycopg/)下载的源文件构建它,我得到了以下错误消息!

Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'

但它确实在那里!!

我对这些错误感到困惑。有人能帮忙吗?

顺便说一下,我sudo所有的命令。而且我使用的是RHEL 5.5。


当前回答

同样在OSX上。安装postgres。应用程序从http://postgresapp.com/,但有同样的问题。

我在该应用程序的内容中找到了pg_config,并将dir添加到$PATH。

它在/Applications/ postgress .app/Contents/Versions/latest/bin。export PATH="/Applications/ postgress .app/Contents/Versions/latest/bin:$PATH"。

其他回答

简单地运行以下命令:

sudo apt install libpq-dev

为我修正了这个问题

我将把这个问题留给下一个不幸的人,尽管提供了所有的解决方案,但他们仍然无法解决这个问题。只需使用sudo pip3安装psycopg2-binary即可

MAC用户

通过HomeBrew添加postgresql包后,可能需要添加openssl路径变量-

出口LIBRARY_PATH = $ LIBRARY_PATH: / usr /地方/ opt / openssl / lib /

然后,您可以再次安装psycopg2包,它应该可以工作。

在安装psycopg2之前,需要升级pip。使用这个命令

pip install --upgrade pip

执行以下命令解决pg_config可执行文件不存在的问题

sudo apt-get install --reinstall libpq-dev