我尝试安装Python包dulwich:

pip install dulwich

但我收到了一条神秘的错误消息:

error: Unable to find vcvarsall.bat

如果我尝试手动安装软件包,也会发生同样的情况:

> python setup.py install
running build_ext
building 'dulwich._objects' extension
error: Unable to find vcvarsall.bat

当前回答

distutils(以及一些setuptools)官方支持的MS VС++版本和安装变体的详细列表,以及如何使用它们,请访问

https://wiki.python.org/moin/WindowsCompilers

它还指定了哪个Win32 Python官方版本需要哪个VC++版本。请注意,MinGW不受官方支持(详见下文)。

简而言之:

对于每个版本,都有一个现成的特定Visual Studio版本。请注意,2012年之前的Express版本不支持x64。尝试对x64使用一个会导致未知错误。对于独立SDK,通常需要从SDK提示符(=设置环境变量)运行安装。对一些人来说,这一要求可以通过一次性调整来解除,而不会产生不利的副作用setuptools支持一些不常见的VC++版本,而不是distutils。据说MinGW“工作”,但仅适用于x86。https://bugs.python.org/issue4709表示其支持的问题在于MinGW本身,甚至自Python 3.5以来,x86也必然会出现问题。

其他回答

我也遇到了同样的错误(我觉得这很愚蠢,而且对错误消息没有任何帮助),尽管有一个C编译器可用,我还是继续遇到问题。

令人惊讶的是,最终对我有用的只是将pip和setuptools升级到最新版本。希望这对其他人有所帮助。

您可以从安装编译版本http://www.lfd.uci.edu/~gohlke/pythonlibs/

我遵守了指示http://springflex.blogspot.ru/2014/02/how-to-fix-valueerror-when-trying-to.html.但什么都没发生。然后我安装了2010 Visual Studio Express(http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express)遵循建议http://blog.python.org/2012/05/recent-windows-changes-in-python-33.html它帮助了我

如果您希望在未安装Visual Studio的Windows机箱上安装pyodbc,另一种选择是使用二进制发行版手动安装pyodcc。

如果您在正在使用的计算机上没有管理员权限,并且正在尝试设置virtualenv,则这特别有用。

步骤:

从这里下载最新的Windows安装程序(pyodbc-X.X.X.X.win-Y-py2.7.exe)使用7-Zip(或WinRAR等)打开安装程序可执行文件提取pyodbc.pyd和pyodbc-X.X-X-py2.7.egg-info,并将它们放在[python安装目录或virtualenv]\Lib\site包中没有步骤4:)

我没有看到任何使用vswhere的答案,我认为这是自Visual Studio 15.2以来正确的方法。

下面是我运行vsvars64.bat的方法(我想这与vsvarsall类似)

def init_vsvars():
    cprint("")
    cprint_header("Initializing vs vars")
    vswhere_path = r"%ProgramFiles(x86)%/Microsoft Visual Studio/Installer/vswhere.exe"
    vswhere_path = path.expandvars(vswhere_path)
    if not path.exists(vswhere_path):
        raise EnvironmentError("vswhere.exe not found at: %s", vswhere_path)

    vs_path = common.run_process(".", vswhere_path,
                                 ["-latest", "-property", "installationPath"])
    vs_path = vs_path.rstrip()

    vsvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvars64.bat")
    # common.run_process(".", vsvars_path, [])
    os.system('"%s"' % vsvars_path)

run_process做了很多事情,但基本上归结为:

    output = ""
    process = subprocess.Popen(
        commandline,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        universal_newlines=True)
    for stdout_line in iter(process.stdout.readline, ""):
        cprint(stdout_line)
        output += stdout_line
    process.stdout.close()

    return_code = process.wait()
    return output