使用pip和virtualenv在Windows XP上安装psycopg2 [英] installing psycopg2 on Windows xp using pip and virtualenv

查看:319
本文介绍了使用pip和virtualenv在Windows XP上安装psycopg2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注Heroku的Heroku上的Django入门文章,并在pip install psycopg2上收到很长一系列错误。 Django 1.5.1和PostgreSQL 9.2.4已经安装好了,是的,postgres \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ $ p> C:\Python27\Scripts>
C:\Python27\Scripts> cd C:\Projects\hellodjango

C:\Projects\hellodjango> pip install psycopg2
下载/解压缩psycopg2
下载psycopg2-2.5.1.tar.gz(684kB):684kB已下载
运行setup.py egg_info包psycopg2

安装收集的包:psycopg2
正在运行setup.py install for psycopg2
建立'psycopg2._psycopg'扩展名
c:\程序文件\微软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):致命错误C1083:无法打开包含文件:'libp
q-fe.h':没有这样的文件或目录
错误:命令'c:\程序文件\微软Visual Studio 9.0\VC\BIN\cl.exe
'失败,退出状态2
完成输出命令C:\Python27\python.exe -cimport setuptools; __
file __ ='c:\\\\\\\\\\'' \\temp\\pip-build-Administrator \\psycopg
2 \\setup.py'; exec(compile(open(__ file __)。read()。replace('\\ \\ n','\\\
'),__file__,
'exec'))install --record c:\docume〜1 \admini〜1 \locals〜1 \temp \ pip-ewegoh-record
\ install-record.txt --single-ver sion-external-managed:
正在运行安装

正在运行的生成

正在运行build_py

正在创建生成

创建build\lib.win32-2.7

创建build\lib.win32-2.7\psycopg2

复制lib\errorcodes.py - > build\lib.win32-2.7\psycopg2

复制lib\extensions.py - > build\lib.win32-2.7\psycopg2

复制lib\extras.py - > build\lib.win32-2.7\psycopg2

复制lib\pool.py - > build\lib.win32-2.7\psycopg2

复制lib\psycopg1.py - > build\lib.win32-2.7\psycopg2

复制lib\tz.py - > build\lib.win32-2.7\psycopg2

复制lib\_json.py - > build\lib.win32-2.7\psycopg2

复制lib\_range.py - > build\lib.win32-2.7\psycopg2

复制lib \__init __。py - > build\lib.win32-2.7\psycopg2

创建build\lib.win32-2.7\psycopg2\测试

复制tests\dbapi20.py - > build\lib.win32-2.7\psycopg2\测试

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

复制tests\testconfig.py - > build \lib.win32-2.7\psycopg2\测试

复制tests\testutils.py - > build \lib.win32-2.7\psycopg2\测试

复制tests\test_async.py - > build \lib.win32-2.7\psycopg2\测试

复制tests\test_bugX000.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_bug_gc.py - > build \lib.win32-2.7\psycopg2\测试

复制tests\test_cancel.py - > build \lib.win32-2.7\psycopg2\测试

复制测试\test_connection.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_copy.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_cursor.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_dates.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_extras_dictcursor.py - > build \lib.win32-2.7\psycopg2\测试

复制测试\test_green.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_lobject.py - > build\lib.win32-2.7\psycopg2\测试

复制测试\test_module.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_notify.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_psycopg2_dbapi20.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_quote.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_transaction.py - > build \lib.win32-2.7\psycopg2\测试

复制tests\test_types_basic.py - > build\lib.win32-2.7\psycopg2\测试

复制tests\test_types_extras.py - > build\lib.win32-2.7\psycopg2\测试

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

复制tests\__init __。py - > build'\\lib.win32-2.7\psycopg2\测试

正在运行build_ext

建筑'psycopg2._psycopg'扩展

创建build \\ \\ temp.win32-2.7

创建build \temp.win32-2.7\Release

创建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):致命错误C1083:无法打开包含文件:'libpq-fe
.h':没有这样的文件或目录

错误:command'c:\ Program Files \ Microsoft Visual Studio 9.0 \VC\BIN\cl.exe'fa
退出状态2

---------------------------------- ------
命令C:\Python27\python.exe -cimport setuptools; __ file __ ='c:\\docume〜1 \\adm
ini〜 1 \\locals〜1 \\temp\\pip-build-Administrator\\psycopg2\\setup.py'; exec(编译
(打开(__文件__)。 ().replace('\r\\\
','\\\
'),__file__,'exec'))install --reco
rd c:\docume〜1 \admini〜1 \locals〜1\temp\pip-ewegoh-record\inst all-record.txt --sin
gle-version-external-managed失败,错误代码1在c:\docume〜1 \admini〜1 \
locals〜1 \temp\\ \\ pip-build-Administrator \psycopg2
存储完整的日志C:\ Documents and Settings \Administrator\pip\pip.log

C:\Projects\ hellodjango>

我该如何解决这个错误?

解决方案

psycopg2构建脚本调用 pg_config.exe 来发现PostgreSQL的位置 include lib 目录(因为它需要 libpq-fe.h libpq。 $ b

通常通过添加你的 C:\ PostgreSQL\bin 目录复制到 PATH 环境变量中。然而,你的问题似乎是你安装了PostgreSQL与Cygwin,因此pg_config脚本告诉使用 / usr / include 但Visual Studio C编译器试图在 c:\usr\\中找到它\\包括,而它实际上位于Cygwin安装目录下,如 c:\cygwin\usr\include



一个快速且肮脏的修复方法是暂时复制您的Cygwin include lib 目录转换为 C:\usr 并再次运行pip。



或者你可以安装PostgreSQL窗口二进制文件并将 PATH 变量指向它们,所以使用的pg_config.exe不会是Cygwin的。



如果您在编译期间也看到这个错误:

 错误:命令'mt.exe'失败,退出状态31 

您必须应用此修正: https://stackoverflow.com/a/20050195



这是关于添加:



($ / code>

到这行后面的msvc9compiler.py:

$ p $ ld_args.append('/ MANIFESTFILE:'+ temp_manifest)
code>

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


I'm following Heroku's "Getting started with Django on Heroku" article and am getting a long series of errors on "pip install psycopg2". Django 1.5.1 and PostgreSQL 9.2.4 are already installed, and yes, the postgres \bin\, \include\ directories are on the 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>

how can I solve this error?

解决方案

The psycopg2 build script calls pg_config.exe to discover the location of your PostgreSQL include and lib directories (since it needs libpq-fe.h and libpq.lib from there).

That's usually solved by adding your C:\PostgreSQL\bin directory to the PATH environment variable.

However your problem seems to be that you have PostgreSQL installed with Cygwin, thus the pg_config script tells to use /usr/include but the Visual Studio C compiler tries to find it in c:\usr\include while it is actually located under the Cygwin installation directory, like c:\cygwin\usr\include.

A quick and dirty fix is to temporarily copy your Cygwin include and lib directories into C:\usr and run pip again.

Or you can install the PostgreSQL windows binaries and point the PATH variable to them, so the pg_config.exe used won't be the Cygwin one.

If you also see this error during compilation:

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

You'll have to apply this fix: https://stackoverflow.com/a/20050195

Which is about adding:

ld_args.append('/MANIFEST')

To msvc9compiler.py after this line:

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

Or you can avoid all this, and use the psycopg2 pre-compiled binaries.

这篇关于使用pip和virtualenv在Windows XP上安装psycopg2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆