安装psycopg2时出现"找不到 -lpq

1 投票
2 回答
1453 浏览
提问于 2025-04-11 09:18

简介: 我正在把我们的Trac SQLite数据库迁移到PostgreSQL后端,为此我需要用到psycopg2。经过一番折腾,我在www.initd.org上下载了最新版本,然后尝试运行 setup.py install。结果没成功,提示我需要mingw。所以我下载并安装了mingw。

问题: 现在当我运行 setup.py build_ext --compiler=mingw32 install 时,出现了以下错误:

running build_ext
building 'psycopg2._psycopg' extension
writing build\temp.win32-2.4\Release\psycopg\_psycopg.def
C:\mingw\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.4\Release\psycopg
\psycopgmodule.o build\temp.win32-2.4\Release\psycopg\pqpath.o build\temp.win32-
2.4\Release\psycopg\typecast.o build\temp.win32-2.4\Release\psycopg\microprotoco
ls.o build\temp.win32-2.4\Release\psycopg\microprotocols_proto.o build\temp.win3
2-2.4\Release\psycopg\connection_type.o build\temp.win32-2.4\Release\psycopg\con
nection_int.o build\temp.win32-2.4\Release\psycopg\cursor_type.o build\temp.win3
2-2.4\Release\psycopg\cursor_int.o build\temp.win32-2.4\Release\psycopg\lobject_
type.o build\temp.win32-2.4\Release\psycopg\lobject_int.o build\temp.win32-2.4\R
elease\psycopg\adapter_qstring.o build\temp.win32-2.4\Release\psycopg\adapter_pb
oolean.o build\temp.win32-2.4\Release\psycopg\adapter_binary.o build\temp.win32-
2.4\Release\psycopg\adapter_asis.o build\temp.win32-2.4\Release\psycopg\adapter_
list.o build\temp.win32-2.4\Release\psycopg\adapter_datetime.o build\temp.win32-
2.4\Release\psycopg\_psycopg.def -LC:\Python24\libs -LC:\Python24\PCBuild -Lc:/P
ROGRA~1/POSTGR~1/8.3/lib -lpython24 -lmsvcr71 -lpq -lmsvcr71 -lws2_32 -ladvapi32
 -o build\lib.win32-2.4\psycopg2\_psycopg.pyd
C:\mingw\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot fin
d -lpq
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

我尝试过的 - 我注意到-L选项中有正斜杠,所以我手动在setup.cfg的library_dirs选项中输入了我的PostgreSQL库目录,但还是不行(然后调用时-L选项变成了反斜杠,但错误信息没有改变)。

2 个回答

1

在Windows上编译扩展可能会有点麻烦。不过,有一些已经编译好的库可以直接使用,大家可以去这个链接看看:http://www.stickpeople.com/projects/python/win-psycopg/

2

你有没有试过在Windows上使用psycopg2的二进制版本?如果这个版本能和你的Python配合使用,那就不需要自己手动编译了。

我看到很多人都在不同的论坛上问这个问题,似乎有一个建议是手动编译PostgreSQL来解决这个问题。

撰写回答