问题:找不到pg_config可执行文件

我在安装psycopg2时遇到问题。尝试执行以下操作时出现以下错误pip install 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。

I am having trouble installing psycopg2. I get the following error when I try to pip install 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

But the problem is pg_config is actually in my PATH; it runs without any problem:

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

I tried adding the pg_config path to the setup.cfg file and building it using the source files I downloaded from their website (http://initd.org/psycopg/) and I get the following error message!

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

But it is actually THERE!!!

I am baffled by these errors. Can anyone help please?

By the way, I sudo all the commands. Also I am on RHEL 5.5.


回答 0

pg_config位于postgresql-devellibpq-devlibpq-develCentos / Cygwin / Babun的Debian / Ubuntu中。)

pg_config is in postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Cygwin/Babun.)


回答 1

在Mac OS X上,我使用自制软件包管理器解决了该问题

brew install postgresql

On Mac OS X, I solved it using the homebrew package manager

brew install postgresql

回答 2

你安装好了python-dev吗?如果已经拥有,请尝试安装libpq-dev

sudo apt-get install libpq-dev python-dev

从文章:如何在virtualenv下安装psycopg2

Have you installed python-dev? If you already have, try also installing libpq-dev

sudo apt-get install libpq-dev python-dev

From the article: How to install psycopg2 under virtualenv


回答 3

同样在OSX上。从http://postgresapp.com/安装了Postgress.app,但存在相同的问题。

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

到了/Applications/Postgres.app/Contents/Versions/latest/bin。所以这个工作:export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"

Also on OSX. Installed Postgress.app from http://postgresapp.com/ but had the same issue.

I found pg_config in that app’s contents and added the dir to $PATH.

It was at /Applications/Postgres.app/Contents/Versions/latest/bin. So this worked: export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH".


回答 4

在高山上,包含的库pg_configpostgresql-dev。要安装,请运行:

apk add postgresql-dev

On alpine, the library containing pg_config is postgresql-dev. To install, run:

apk add postgresql-dev

回答 5

这是在CentOS上首次安装对我有用的东西:

sudo yum install postgresql postgresql-devel python-devel

在Ubuntu上,只需使用等效的apt-get软件包。

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

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

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

确保包括正确的路径。就这样 :)

This is what worked for me on CentOS, first install:

sudo yum install postgresql postgresql-devel python-devel

On Ubuntu just use the equivilent apt-get packages.

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

And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:

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

Make sure to include the correct path. Thats all :)


回答 6

apt-get build-dep python-psycopg2
apt-get build-dep python-psycopg2

回答 7

您应该添加在Ubuntu上的Postgres中使用的python要求。跑:

sudo apt-get install libpq-dev python-dev

You should add python requirements used in Postgres on Ubuntu. Run:

sudo apt-get install libpq-dev python-dev

回答 8

综上所述,我也面临着完全相同的问题。在阅读了很多stackoverflow帖子和在线博客之后,对我有用的最终解决方案是:

1)在安装psycopg2之前,应先安装PostgreSQL(开发版或任何稳定版本)。

2)在安装psycopg2之前,必须显式设置pg_config文件(该文件通常位于PostgreSQL安装文件夹的bin文件夹中)。就我而言,PostgreSQL的安装路径为:

/opt/local/lib/postgresql91/

因此,为了显式设置pg_config文件的PATH,我在终端中输入了以下命令:

PATH=$PATH:/opt/local/lib/postgresql91/bin/

此命令可确保当您尝试通过pip安装psycopg2时,它将自动找到pg_config的路径。

我还在我的博客上发布了有关trace及其解决方案的完整错误,您可能希望参考。它适用于Mac OS X,但是pg_config PATH问题是通用的,也适用于Linux。

Just to sum up, I also faced exactly same problem. After reading a lot of stackoverflow posts and online blogs, the final solution which worked for me is this:

1) PostgreSQL(development or any stable version) should be installed before installing psycopg2.

2) The pg_config file (this file normally resides in the bin folder of the PostgreSQL installation folder) PATH had to be explicitly setup before installing psycopg2. In my case, the installation PATH for PostgreSQL is:

/opt/local/lib/postgresql91/

so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal:

PATH=$PATH:/opt/local/lib/postgresql91/bin/

This command ensures that when you try to pip install psycopg2, it would find the PATH to pg_config automatically this time.

I have also posted a full error with trace and its solution on my blog which you may want to refer. Its for Mac OS X but the pg_config PATH problem is generic and applicable to Linux also.


回答 9

sudo apt-get install libpq-dev 在Ubuntu 15.4上为我工作

sudo apt-get install libpq-dev works for me on Ubuntu 15.4


回答 10

在Linux上Mint sudo apt-get install libpq-dev为我工作。

On Linux Mint sudo apt-get install libpq-dev worked for me.


回答 11

您可以使用pip或在任何平台上安装预编译的二进制文件conda

python -m pip install psycopg2-binary

要么

conda install psycopg2

请注意,psycopg2-binary pypi页面建议在生产中从源代码构建:

二进制软件包是开发和测试的实际选择,但在生产中,建议使用从源构建的软件包

要使用从源构建的软件包,请使用python -m pip install psycopg2。该过程将需要几个依赖项(文档)(重点是我的):

  • 交流编译器
  • Python的头文件。它们通常安装在python-dev之类的软件包中。诸如错误消息:Python.h:没有这样的文件或目录表示缺少Python标头。
  • libpq的头文件。它们通常安装在libpq-dev之类的软件包中。如果出现错误:libpq-fe.h:没有此类文件或目录,您将丢失它们。
  • pg_config程序:它通常是由安装的libpq-dev的包,但有时它是不是在路径目录。将它放在PATH中可以大大简化安装,因此请尝试运行pg_config –version:如果返回错误或意外的版本号,请找到包含正确libpq版本附带的pg_config的目录(通常是/ usr / lib / postgresql / XY / bin /)并将其添加到PATH: $ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH 您仅需要pg_config来编译psycopg2,而无需常规使用。

You can install pre-compiled binaries on any platform with pip or conda:

python -m pip install psycopg2-binary

or

conda install psycopg2

Please be advised that the psycopg2-binary pypi page recommends building from source in production:

The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources

To use the package built from sources, use python -m pip install psycopg2. That process will require several dependencies (documentation) (emphasis mine):

  • A C compiler.
  • The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.
  • The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.
  • The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config –version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually /usr/lib/postgresql/X.Y/bin/) and add it to the PATH: $ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH You only need pg_config to compile psycopg2, not for its regular usage.

回答 12

UPDATE /etc/yum.repos.d/CentOS-Base.repo、[base]和[updates]部分
ADD exclude = postgresql *

curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr  
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm

yum install postgresql  
yum install postgresql-devel

PATH=$PATH:/usr/pgsql-9.1/bin/

pip install psycopg2

UPDATE /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
ADD exclude=postgresql*

curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr  
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm

yum install postgresql  
yum install postgresql-devel

PATH=$PATH:/usr/pgsql-9.1/bin/

pip install psycopg2

回答 13

对于运行OS X的用户,此解决方案对我有用:

1)安装Postgres.app:

http://www.postgresql.org/download/macosx/

2)然后打开终端并运行以下命令,将其显示为{{version}}的位置替换为Postgres版本号:

导出PATH = $ PATH:/Applications/Postgres.app/Contents/Versions / {{version}} / bin

例如

导出PATH = $ PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin

For those running OS X, this solution worked for me:

1) Install Postgres.app:

http://www.postgresql.org/download/macosx/

2) Then open the Terminal and run this command, replacing where it says {{version}} with the Postgres version number:

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/{{version}}/bin

e.g.

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


回答 14

尝试将其添加到PATH:

PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2

Try to add it to PATH:

PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2

回答 15

Ali的解决方案对我有用,但是我在查找bin文件夹位置时遇到了麻烦。在Mac OS X上查找路径的快速方法是打开psql(顶部菜单栏中有一个快速链接)。这将打开一个单独的终端窗口,在第二行,您的Postgres安装路径将如下所示:

My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;

您的pg_config文件在该bin文件夹中。因此,在安装psycopg2之前,请设置pg_config文件的路径:

PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/

或较新版本:

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

然后安装psycopg2。

Ali’s solution worked for me but I was having trouble finding the bin folder location. A quick way to find the path on Mac OS X is to open psql (there’s a quick link in the top menu bar). This will open a separate terminal window and on the second line the path of your Postgres installation will appear like so:

My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;

Your pg_config file is in that bin folder. Therefore, before installing psycopg2 set the path of the pg_config file:

PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/

or for newer version:

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

Then install psycopg2.


回答 16

在安装psycopg2之前,您需要升级您的pip。使用此命令

pip install --upgrade pip

You need to upgrade your pip before installing psycopg2. Use this command

pip install --upgrade pip

回答 17

我将把这个留给下一个不幸的灵魂,尽管所有提供的解决方案都无法解决这个问题。只需使用sudo pip3 install psycopg2-binary

I’m going to leave this here for the next unfortunate soul who can’t get around this problem despite all the provided solutions. Simply use sudo pip3 install psycopg2-binary


回答 18

刚刚通过以下方法解决了Cent OS 7中的问题:

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

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

Just solved the problem in Cent OS 7 by:

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

make sure your PostgreSql version matches the right version above.


回答 19

在Mac OS X上,如果您使用的是Postgres App(http://postgresapp.com/):

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

无需在此命令中指定Postgres的版本。它将始终指向最新。

并做

pip install psycopg2

PS:如果更改未反映出您可能需要重新启动终端/命令提示符

资源

On Mac OS X and If you are using Postgres App (http://postgresapp.com/):

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

No need to specify version of Postgres in this command. It will be always pointed to latest.

and do

pip install psycopg2

P.S: If Changes doesn’t reflect you may need to restart the Terminal/Command prompt

Source


回答 20

安装python-psycopg2在Arch Linux上为我解决了这个问题:

pacman -S python-psycopg2

Installing python-psycopg2 solved it for me on Arch Linux:

pacman -S python-psycopg2

回答 21

在Windows上,您可能需要安装PsycopgWindows端口,该端口psycopg的文档中建议使用。

On Windows, You may want to install the Windows port of Psycopg, which is recommended in psycopg’s documentation.


回答 22

在MacOS上,最简单的解决方案是将正确的二进制文件符号链接到Postgres软件包下。

sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_config

这是相当无害的,并且如果需要,所有应用程序都可以在系统范围内使用它。

On MacOS, the simplest solution will be to symlink the correct binary, that is under the Postgres package.

sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_config

This is fairly harmless, and all the applications will be able to use it system wide, if required.


回答 23

sudo yum安装postgresql-devel(centos6X)

点安装psycopg2 == 2.5.2

sudo yum install postgresql-devel (centos6X)

pip install psycopg2==2.5.2


回答 24

在这里,为了确保OS X的完整性:如果从MacPorts安装PostgreSQL,则pg_config将位于 /opt/local/lib/postgresql94/bin/pg_config

安装MacPorts时,它已经添加了 /opt/local/bin到PATH中。

因此,这将解决问题: $ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config

现在pip install psycopg2将可以pg_config毫无问题地运行。

Here, for OS X completeness: if you install PostgreSQL from MacPorts, pg_config will be in /opt/local/lib/postgresql94/bin/pg_config.

When you installed MacPorts, it already added /opt/local/bin to your PATH.

So, this will fix the problem: $ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config

Now pip install psycopg2 will be able to run pg_config without issues.


回答 25

对于使用zshshell的macOS Catalina 上也安装了postgres应用程序的用户

打开~/.zshrc文件,并添加以下行:

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

然后关闭所有终端,重新打开它们,您将解决问题。

如果您不想关闭终端,只需输入要继续使用的终端即可source ~/.zshrc

To those on macOS Catalina using the zsh shell who have also installed the postgres app:

Open your ~/.zshrc file, and add the following line:

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

Then close all your terminals, reopen them, and you’ll have resolved your problem.

If you don’t want to close your terminals, simply enter source ~/.zshrc in whatever terminal you’d like to keep working on.


回答 26

对于mac用户,扩展您的path变量以包括PostgreSQL这样的export PATH=$PATH:/Library/PostgreSQL/12/bin

For mac users, extend your path variable to include PostgreSQL like this export PATH=$PATH:/Library/PostgreSQL/12/bin.


回答 27

这是我设法安装psycopg2的方法

$ wget http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.3.tar.gz
$ tar -xzf psycopg2-2.5.3.tar.gz
$ cd psycopg2-2.5.3
$ pip install .

This is how I managed to install psycopg2

$ wget http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.3.tar.gz
$ tar -xzf psycopg2-2.5.3.tar.gz
$ cd psycopg2-2.5.3
$ pip install .

回答 28

我敢肯定,您会遇到与我相同的“问题”,因此,我将为您提供极为简单的解决方案…

在您的情况下,您需要添加到$ PATH(或作为命令参数)的实际路径是:

/usr/pgsql-9.1/bin/pg_config

/usr/pgsql-9.1/bin

例如,如果您随后运行python setup.py脚本,则可以这样运行它:

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

可能为时已晚,但仍然是最简单的解决方案。

之后编辑:

在进一步测试下,我发现如果您最初以以下形式将路径添加到pg_config

/usr/pgsql-9.1/bin

(在../bin之后没有/ pg_config)并运行pip install命令,它将起作用。

但是,如果您随后决定按照说明运行python setup.py,则必须在….. / bin之后使用/ pg_config指定路径,即

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

I am pretty sure you’ve experienced the same “problem” i did, therefore I’ll offer you the extremely easy solution…

In your case, the actual path that you need to add to $PATH (or as a command param) is:

/usr/pgsql-9.1/bin/pg_config

not

/usr/pgsql-9.1/bin

E.g. if you run the python setup.py script afterwards, you would run it like this:

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

Probably too late, but still the easiest solution.

LATER EDIT:

Under further test I found out that if you initially add the path to pg_config in the form

/usr/pgsql-9.1/bin

(without /pg_config after …../bin) and run the pip install command it will work.

However, if you then decide to follow the indication to run python setup.py, you will have to specify the path with /pg_config after …../bin, i.e.

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

回答 29

对于CentOS / RedHat,请确保这/etc/alternatives/pgsql-pg_config是一个不间断的符号链接

for CentOS/RedHat make sure that /etc/alternatives/pgsql-pg_config is a non-broken symlink


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。