我在安装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。


当前回答

对于mac用户,扩展路径变量以包含PostgreSQL,如export path =$ path:/Library/PostgreSQL/12/bin。

其他回答

对于那些没有在本地安装Postgresql并希望将其作为Docker容器运行的人。您应该使用psycopg2-binary。

刚刚解决了问题在Cent OS 7:

export PATH=$PATH:/usr/pgsql-9.5/bin

确保你的PostgreSql版本与上面的正确版本匹配。

这是我在CentOS上使用的方法,首先安装:

sudo yum install postgresql postgresql-devel python-devel

在Ubuntu上使用等价的apt-get包即可。

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

现在在pip install中包含到你的postgresql二进制目录的路径,这应该适用于Debain或基于RHEL的Linux:

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

确保包含正确的路径。就这些。

我遇到这个问题是因为我没有安装postgres。如果你有brew安装运行

brew install postgresql

这应该可以解决问题。

你必须安装libpq-dev/ PostgreSQL -libs,这是编译C程序链接到libpq库的头文件和静态库,以便与PostgreSQL数据库后端通信。

在Arch上运行:

$ sudo pacman -S postgresql-libs

在Debian和Ubuntu上:

$ sudo apt-get install libpq-dev

在Mac OS X上:

$ brew install postgresql

在Red Hat/CentOS/Fedora上:

$ sudo yum install postgresql-devel