能否在使用vc9编译的Python中在Windows上运行psycopg2?

3

我有一个类似于ImportError: DLL load failed : - when trying to import psycopg2 library的问题。

我正在尝试使用Python 2.6.5和Visual Studio 2008(vc9)构建运行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”。那是什么?

  • Eric
1个回答

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接