3

我有一个类似于ImportError: DLL load failed : - 尝试导入 psycopg2 库时的问题

我正在尝试使用使用 Visual Studio 2008 (vc9) 构建的 Python 2.6.5 运行 psycopg2。我收到此错误:

from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: DLL load failed: The operating system cannot run %1.

来自 PostGres 8.4 的 libpg.dll 在路径中。如果我使用 vc6 构建的 python 构建 psycopg2,它将运行良好。但问题是我需要它来使用 vc9 构建的 Python。

我引用的页面提到使用旧版本。当我尝试构建版本 2.12.0(甚至 2.10.0)时,我收到此错误:

C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W
3 /GS- /DNDEBUG -DPSYCOPG_DEFAULT_PYDATETIME=1 "-DPSYCOPG_VERSION=\"2.0.10 (dt d
ec ext pq3)\"" -DPG_VERSION_HEX=0x080401 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BO
OLEAN=1 -DHAVE_PQFREEMEM=1 -DHAVE_PQPROTOCOL3=1 -IC:\Python26\include -IC:\Pytho
n26\PC -I. -Ic:/apps/POSTGR~1/8.4/include -Ic:/apps/POSTGR~1/8.4/include/server
/Tcpsycopg\connection_int.c /Fobuild\temp.win32-2.6\Release\psycopg\connection_i
nt.obj /Wp64
cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be
removed in a future release
connection_int.c
psycopg\connection_int.c(70) : error C2143: syntax error : missing ';' before 't
ype'
psycopg\connection_int.c(71) : error C2065: 'notice' : undeclared identifier
psycopg\connection_int.c(71) : warning C4047: '=' : 'int' differs in levels of i
ndirection from 'connectionObject_notice *'
psycopg\connection_int.c(73) : error C2065: 'notice' : undeclared identifier
psycopg\connection_int.c(73) : warning C4047: '!=' : 'int' differs in levels of
indirection from 'void *'

等等....查看C代码,没有包装struct connectionObject_notice定义的条件代码,所以我看不出什么会触发这个错误。

最后,上述帖子中的一张海报提到了“PG6000”。那是什么?

  • 埃里克
4

1 回答 1

2

也许你应该安装 Windows SDK 7.0。

我的系统中安装了 vs2005/vs2008/vc2010 和一些 windows SDK,当我安装 psycopg2-2.4.2 python 包时使用“python setup.py install”,
它提示我需要“mt.exe”;
所以我将“C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin”添加到路径中,然后它就可以构建了。但是 python -c "import psycopg2" 仍然失败,所以我将 PostgreSQL 客户端安装路径:"...\PostgreSQL\8.4\bin" 添加到系统路径,然后一切正常。

于 2011-06-21T13:35:18.923 回答