我尝试安装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://www.lfd.uci.edu/~gohlke/pythonlibs/

其他回答

如果您安装了mingw

pip install --global-option build_ext --global-option --compiler=mingw32 packagename

有效,迫使pip使用mingw编译器而不是Microsoft的编译器进行编译。请参见此处https://github.com/pypa/pip/issues/18有关详细信息(上一篇文章)。

我想在Windows 10上使用Python 2.7运行pysph,但没有找到vcvarsall.bat(来自distutils)

我的解决方案如下:

安装Microsoft Visual C++for Python 2.7(如@Michael建议的那样)

在Windows 10上,它安装到(我的用户名是Andreas):

C:\Users\Andreas\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

将环境变量VS90COMNTOOLS设置为Visual C++for Python 2.7的安装路径(请参见上面的路径)。

如果仍然不起作用,则在模块中进行修改

C:/Python27/lib/distutils

文件msvc9compiler.py。在其中查找函数Find_vcvarsall并执行以下修改。

更换管路:

productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")

with

productdir = os.path.join(toolsdir)

在我的案例中,这就是vcvarsall.bat所在的位置(请检查,vcvarsall.bat在您的安装中)。

使用此链接下载并安装Visual C++2015生成工具。它将自动下载visualcppbuildtools_full.exe并安装Visual C++14.0,而无需实际安装Visual Studio。安装完成后,重试pip安装,您将不会再次出现错误。

我已经在以下平台和版本上测试了它:

Python 3.6 on Windows 7 64-bit
Python 3.7 on Windows Server 2016 (64-bit system)
Python 3.8 on Windows 10 64-bit

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

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