我尝试安装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

当前回答

我遵守了指示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它帮助了我

其他回答

以下步骤为我解决了这个问题,我正尝试使用cython扩展创建设置。

安装Microsoft Visual C++编译器Python 2.7版默认安装位置为@C: \Users\PC user\AppData\Local\Programs\Common\Microsoft\Visual C++对于Python这实际上可能会解决问题,请在继续之前测试一次。如果失败,请检查VC中的位置++对于python,vcvarsall.bat文件位于打开msvc9compiler.py记事本中distutils包的文件。在我的箱子里@C: \Anaconda2\Lib\distutils\msvc9compiler.py find_vcvarsall函数在此文件中,通过打印版本来确定VC的版本论点对于Python 2.7,可能是9.0现在创建一个环境变量VS90COMNTOOLS,指向C: \Users\PC user\AppData\Local\Programs\Common\Microsoft\Visual C++用于Python\9.0\VC\bin出于某种原因,distutils期望vcvarsall.bat文件应位于VCdir中,但对于python工具则为VC++它位于9.0的根目录中。要解决此问题,请从path.join(大致围绕第247行)#productdir=os.path.join(toolsdir,os.pardir,os.pardir,“VC”)productdir=os.path.join(toolsdir,os.pardir,os.pardir)

以上步骤为我解决了问题。

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

你可以用easy_install代替pip,这对我很有用。

我没有看到任何使用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

对于Python 3.4,依赖于Visual Studio 2010。安装Visual C++2010 Express为我解决了这个问题。

欺骗它使用VS 2008或2013安装,而我碰巧没有使用。