1

我正在关注 Heroku 的“Heroku 上的 Django 入门”文章,并且在“pip install psycopg2”上遇到了一系列错误。已经安装了 Django 1.5.1 和 PostgreSQL 9.2.4,是的,postgres \bin\、\include\ 目录在 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>

我该如何解决这个错误?

4

1 回答 1

0

psycopg2 构建脚本调用pg_config.exe以发现 PostgreSQLincludelib目录的位置(因为它需要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.

include一个快速而肮脏的修复方法是将您的 Cygwin和lib目录临时复制到C:\usr并再次运行 pip。

或者您可以安装 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 预编译的二进制文件。

于 2014-03-28T03:28:22.677 回答