在Cygwin中安装psycopg2时出错

9 投票
2 回答
3563 浏览
提问于 2025-04-17 03:34

我正在尝试在cygwin上安装psycopg2,但还没有成功。

出现的错误是:

Gaurav@gauravpc ~/FieldAgentWeb/FieldAgentWeb
$ easy_install psycopg2
Searching for psycopg2
Reading http://pypi.python.org/simple/psycopg2/
Reading http://initd.org/psycopg/
Reading http://initd.org/projects/psycopg2
Best match: psycopg2 2.4.2
Downloading http://initd.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.2.tar.gz
Processing psycopg2-2.4.2.tar.gz
Running psycopg2-2.4.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-QBYpxH
/psycopg2-2.4.2/egg-dist-tmp-gcLa5F
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'.
error: Directory not empty <built-in function rmdir> /tmp/easy_install-QBYpxH/ps
ycopg2-2.4.2/tests

之后我试着去找pg_config这个文件,但在网上找不到。

2 个回答

16

我今天成功安装了psycopg2,而不需要在Windows上安装PostgreSQL(因为我的数据库已经在另一台服务器上设置好了,我只需要用一个依赖于psycopg2的Python包来连接它,所以我不需要完整的安装)。

根据这个链接 pg_config executable not found,我在Cygwin的设置中安装了 postgresql-devel libpq-dev(这两个是必要的,顺便说一下,我还安装了很多与PostgreSQL相关的其他包,比如postgresql-client、postgresql-plpython和libpq5)。

之后我就可以顺利运行 pip install psycopg2 了。

5

pg_config是你安装的PostgreSQL的一部分。它位于你本地安装的bin文件夹里(比如说C:\Program Files (x86)\PostgreSQL\9.0\bin)。你需要把这个文件夹添加到你的搜索路径里,然后再试着构建一次。

撰写回答