postgresql 错误:在 windows7 中安装 psycopg2 时无法找到 vcvarsall.bat

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21074191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:16:02  来源:igfitidea点击:

error: Unable to find vcvarsall.bat in installing psycopg2 in windows7

pythondjangopostgresqlwindows-7psycopg2

提问by gadss

Im using Windows 7 for developing Django 1.3.7 using PostgreSQL 9.3 as database. on my settings.pyI set DATABASE_ENGINE = 'django.db.backends.postgresql_psycopg2'but when I try to execute python manage.py syncdbI got this error:

我使用 Windows 7 开发 Django 1.3.7,使用 PostgreSQL 9.3 作为数据库。在我的settings.py设置上,DATABASE_ENGINE = 'django.db.backends.postgresql_psycopg2'但是当我尝试执行时python manage.py syncdb出现此错误:

C:\Django-Proj\myproj\myproj>python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 61, in <module>
    execute_manager(settings)
  File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
438, in execute_manager
    utility.execute()
  File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
67, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
    __import__(name)
  File "c:\Python27\lib\site-packages\django\core\management\commands\syncdb.py"
, line 7, in <module>
    from django.core.management.sql import custom_sql_for_model, emit_post_sync_
signal
  File "c:\Python27\lib\site-packages\django\core\management\sql.py", line 6, in
 <module>
    from django.db import models
  File "c:\Python27\lib\site-packages\django\db\__init__.py", line 78, in <modul
e>
    connection = connections[DEFAULT_DB_ALIAS]
  File "c:\Python27\lib\site-packages\django\db\utils.py", line 93, in __getitem
__
    backend = load_backend(db['ENGINE'])
  File "c:\Python27\lib\site-packages\django\db\utils.py", line 33, in load_back
end
    return import_module('.base', backend_name)
  File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
    __import__(name)
  File "c:\Python27\lib\site-packages\django\db\backends\postgresql_psycopg2\bas
e.py", line 24, in <module>
    raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No m
odule named psycopg2

Then I try to install psycopg2 but it got an error:

然后我尝试安装 psycopg2,但出现错误:

C:\>pip install psycopg2
Downloading/unpacking psycopg2
  Running setup.py (path:c:\users\samuel\appdata\local\temp\pip_build_Samuel\psy
copg2\setup.py) egg_info for package psycopg2

Installing collected packages: psycopg2
  Running setup.py install for psycopg2
    building 'psycopg2._psycopg' extension
    error: Unable to find vcvarsall.bat
    Complete output from command C:\Python27\python.exe -c "import setuptools, t
okenize;__file__='c:\users\samuel\appdata\local\temp\pip_build_Samuel\psy
copg2\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().r
eplace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\samuel\appda
ta\local\temp\pip-dsnjrg-record\install-record.txt --single-version-externally-m
anaged --compile:
    running install

running build

running build_py

creating build

creating build\lib.win-amd64-2.7

creating build\lib.win-amd64-2.7\psycopg2

copying lib\errorcodes.py -> build\lib.win-amd64-2.7\psycopg2

copying lib\extensions.py -> build\lib.win-amd64-2.7\psycopg2

copying lib\extras.py -> build\lib.win-amd64-2.7\psycopg2

copying lib\pool.py -> build\lib.win-amd64-2.7\psycopg2

copying lib\psycopg1.py -> build\lib.win-amd64-2.7\psycopg2

copying lib\tz.py -> build\lib.win-amd64-2.7\psycopg2

copying lib\_json.py -> build\lib.win-amd64-2.7\psycopg2

copying lib\_range.py -> build\lib.win-amd64-2.7\psycopg2

copying lib\__init__.py -> build\lib.win-amd64-2.7\psycopg2

creating build\lib.win-amd64-2.7\psycopg2\tests

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

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

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

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

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

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

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

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

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

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

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

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

copying tests\test_extras_dictcursor.py -> build\lib.win-amd64-2.7\psycopg2\test
s

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

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

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

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

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


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

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

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

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

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

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

running build_ext

building 'psycopg2._psycopg' extension

error: Unable to find vcvarsall.bat

----------------------------------------
Cleaning up...
Command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\use
rs\samuel\appdata\local\temp\pip_build_Samuel\psycopg2\setup.py';exec(com
pile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __f
ile__, 'exec'))" install --record c:\users\samuel\appdata\local\temp\pip-dsnjrg-
record\install-record.txt --single-version-externally-managed --compile failed w
ith error code 1 in c:\users\samuel\appdata\local\temp\pip_build_Samuel\psycopg2

Storing debug log for failure in C:\Users\Samuel\pip\pip.log

Does anyone have an idea about my case? thanks in advance

有人知道我的案子吗?提前致谢

回答by ajknzhol

There is the huge list of Unofficial Windows Binaries for Python Extension Packages which are extremely useful for Windows users.

Python 扩展包的非官方 Windows 二进制文件的大量列表对 Windows 用户非常有用。

http://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg

http://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg

Go to the link, download and install it and you are good to go.

转到链接,下载并安装它,您就可以开始了。

Cheers !

干杯!

回答by Craig Ringer

Don't try to compile psycopg2 for Windows. You'll need a Visual Studio install or Windows SDK and all sorts of other mess.

不要尝试为 Windows 编译 psycopg2。您将需要安装 Visual Studio 或 Windows SDK 以及各种其他杂乱无章的东西。

Just grab a binary build: http://initd.org/psycopg/download/

只需获取一个二进制构建:http: //initd.org/psycopg/download/