开发者

Python and Postgres on Red Hat

I've been having trouble installing psycopg2 on linux. I receive the following error when I try to import psycopg2.

Python 2.6.4 (r264:75706, Nov 19 2009, 14:52:22) 
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call las开发者_如何学JAVAt):
   File "<stdin>", line 1, in <module>
   File "/usr/local/lib/python2.6/site-packages/psycopg2/__init__.py", line 69, in <module>
   from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: /usr/local/lib/python2.6/site-packages/psycopg2/_psycopg.so: undefined symbol: PQserverVersion

I'm using Postgresql 9.0.1, Psycopg2 2.2.2, Python 2.6.4, and RHEL 4.

The problem is identical to this question from a year ago, which was never answered: http://code.activestate.com/lists/python-list/169772/.

Has anyone seen this error? Any suggestions would be much appreciated.

EDIT: This same combination of Postgresql 9.0.1, Psycopg2 2.2.2, and Python 2.6.4 worked fine on my mac (snow leopard). So I expect the problem is something particular to Red Hat.


Red hat comes with a build of postgres, which can conflict with a custom installation. Python uses pg_config to configure the psycopg2 build. I installed postgres into /usr/local/pgsql/, but calling which pg_config returned /usr/bin/pg_config/.

In the psycopg2 build directory, there is a file setup.cfg, which lets you explicitly define the path to pg_config:

pg_config=/usr/local/pgsql/bin/pg_config

Setting this one parameter and re-compiling solved my problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜