使用PIP和的virtualenv在Windows XP上安装psycopg2(installing

2019-10-18 08:38发布

我下面Heroku的“入门的Django在Heroku”的文章和我得到的“点子安装psycopg2”一长串错误。 Django的1.5.1和PostgreSQL 9.2.4已经安装了,是的,Postgres的\ BIN \,\ \包含目录是在PATH。

 C:\Python27\Scripts>
C:\Python27\Scripts>cd C:\Projects\hellodjango

C:\Projects\hellodjango>pip install psycopg2
Downloading/unpacking psycopg2
  Downloading psycopg2-2.5.1.tar.gz (684kB): 684kB downloaded
  Running setup.py egg_info for package psycopg2

Installing collected packages: psycopg2
  Running setup.py install for psycopg2
    building 'psycopg2._psycopg' extension
    c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /M
D /W3 /GS- /DNDEBUG -DPSYCOPG_DEFAULT_PYDATETIME=1 "-DPSYCOPG_VERSION=\"2.5.1 (d
t dec pq3 ext)\"" -DPG_VERSION_HEX=0x08020B -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW
_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -IC:\Python27\include -IC:\Python27\PC -I. -I/usr/
include -I/usr/include/postgresql/server /Tcpsycopg\psycopgmodule.c /Fobuild\tem
p.win32-2.7\Release\psycopg\psycopgmodule.obj
    psycopgmodule.c
    .\psycopg/psycopg.h(31) : fatal error C1083: Cannot open include file: 'libp
q-fe.h': No such file or directory
    error: command '"c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe"
' failed with exit status 2
    Complete output from command C:\Python27\python.exe -c "import setuptools;__
file__='c:\\docume~1\\admini~1\\locals~1\\temp\\pip-build-Administrator\\psycopg
2\\setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__,
 'exec'))" install --record c:\docume~1\admini~1\locals~1\temp\pip-ewegoh-record
\install-record.txt --single-version-externally-managed:
    running install

running build

running build_py

creating build

creating build\lib.win32-2.7

creating build\lib.win32-2.7\psycopg2

copying lib\errorcodes.py -> build\lib.win32-2.7\psycopg2

copying lib\extensions.py -> build\lib.win32-2.7\psycopg2

copying lib\extras.py -> build\lib.win32-2.7\psycopg2

copying lib\pool.py -> build\lib.win32-2.7\psycopg2

copying lib\psycopg1.py -> build\lib.win32-2.7\psycopg2

copying lib\tz.py -> build\lib.win32-2.7\psycopg2

copying lib\_json.py -> build\lib.win32-2.7\psycopg2

copying lib\_range.py -> build\lib.win32-2.7\psycopg2

copying lib\__init__.py -> build\lib.win32-2.7\psycopg2

creating build\lib.win32-2.7\psycopg2\tests

copying tests\dbapi20.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\dbapi20_tpc.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\testconfig.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\testutils.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_async.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_bugX000.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_bug_gc.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_cancel.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_connection.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_copy.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_cursor.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_dates.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_extras_dictcursor.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_green.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_lobject.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_module.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_notify.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_psycopg2_dbapi20.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_quote.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_transaction.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_types_basic.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_types_extras.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\test_with.py -> build\lib.win32-2.7\psycopg2\tests

copying tests\__init__.py -> build\lib.win32-2.7\psycopg2\tests

running build_ext

building 'psycopg2._psycopg' extension

creating build\temp.win32-2.7

creating build\temp.win32-2.7\Release

creating build\temp.win32-2.7\Release\psycopg

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.5.1 (dt de
c pq3 ext)\"" -DPG_VERSION_HEX=0x08020B -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOO
LEAN=1 -DHAVE_PQFREEMEM=1 -IC:\Python27\include -IC:\Python27\PC -I. -I/usr/incl
ude -I/usr/include/postgresql/server /Tcpsycopg\psycopgmodule.c /Fobuild\temp.wi
n32-2.7\Release\psycopg\psycopgmodule.obj

psycopgmodule.c

.\psycopg/psycopg.h(31) : fatal error C1083: Cannot open include file: 'libpq-fe
.h': No such file or directory

error: command '"c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe"' fa
iled with exit status 2

----------------------------------------
Command C:\Python27\python.exe -c "import setuptools;__file__='c:\\docume~1\\adm
ini~1\\locals~1\\temp\\pip-build-Administrator\\psycopg2\\setup.py';exec(compile
(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --reco
rd c:\docume~1\admini~1\locals~1\temp\pip-ewegoh-record\install-record.txt --sin
gle-version-externally-managed failed with error code 1 in c:\docume~1\admini~1\
locals~1\temp\pip-build-Administrator\psycopg2
Storing complete log in C:\Documents and Settings\Administrator\pip\pip.log

C:\Projects\hellodjango>

我怎样才能解决这个问题?

Answer 1:

该psycopg2构建脚本调用pg_config.exe去发现你的PostgreSQL地点includelib目录(因为它需要libpq-fe.hlibpq.lib从那里)。

这通常是通过添加您解决C:\PostgreSQL\bin目录到PATH环境变量。

但是你的问题似乎是,你有Cygwin的安装PostgreSQL的,因此pg_config脚本告诉使用/usr/include ,但在Visual Studio C编译器试图找到它在c:\usr\include ,而它实际上是在Cygwin下位于安装目录,如c:\cygwin\usr\include

一个快速和肮脏的解决办法是暂时复制你的Cygwin includelib目录为C:\usr并再次运行点子。

或者你可以安装PostgreSQL的Windows可执行文件和指向PATH变量给他们,所以使用的pg_config.exe不会是Cygwin的一个。

如果您还编译过程中看到此错误:

error: command 'mt.exe' failed with exit status 31

你必须应用此修复程序: https://stackoverflow.com/a/20050195

这大约是添加:

ld_args.append('/MANIFEST')

这一行后msvc9compiler.py:

ld_args.append('/MANIFESTFILE:' + temp_manifest)

或者你可以逃避这一切,并使用psycopg2预编译的二进制文件。



文章来源: installing psycopg2 on Windows xp using pip and virtualenv