本文翻译自:pg_config executable not found
I am having trouble installing psycopg2. 我在安装psycopg2时遇到问题。 I get the following error when I try to pip install 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
But the problem is pg_config
is actually in my PATH
; 但是问题是pg_config
实际上在我的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! 我尝试将pg_config路径添加到setup.cfg
文件,并使用从其网站( http://initd.org/psycopg/ )下载的源文件进行构建,然后得到以下错误消息!
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. 顺便说一句,我sudo
所有命令。 Also I am on RHEL 5.5. 我也在使用RHEL 5.5。
参考:https://stackoom.com/question/mkba/找不到pg-config可执行文件
pg_config
在postgresql-devel
(Debian / Ubuntu中的libpq-dev
,在Cygwin / Babun上的libpq-devel
)。
尝试将其添加到PATH:
PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2
Have you installed python-dev
? 您安装了python-dev
吗? If you already have, try also installing libpq-dev
如果已经拥有,请尝试同时安装libpq-dev
sudo apt-get install libpq-dev python-dev
From the article: How to install psycopg2 under virtualenv 从文章: 如何在virtualenv下安装psycopg2
apt-get build-dep python-psycopg2
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: 在阅读了很多stackoverflow帖子和在线博客之后,对我有用的最终解决方案是:
1) PostgreSQL(development or any stable version) should be installed before installing psycopg2. 1)在安装psycopg2之前,应先安装PostgreSQL(开发版或任何稳定版本)。
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. 2)在安装psycopg2之前,必须显式设置pg_config文件(该文件通常位于PostgreSQL安装文件夹的bin文件夹中)。 In my case, the installation PATH for PostgreSQL is: 就我而言,PostgreSQL的安装路径为:
/opt/local/lib/postgresql91/
so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal: 因此,为了显式设置pg_config文件的PATH,我在终端中输入了以下命令:
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. 此命令可确保当您尝试通过pip安装psycopg2时,它将自动找到pg_config的路径。
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. 它适用于Mac OS X,但是pg_config PATH问题是通用的,也适用于Linux。