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

当前回答

我有python 2.73和windows 7。对我有效的解决方案是:

将mingw32的bin目录添加到环境变量:用C:\programs\mingw\bin追加PATH;已创建distutils.cfg,位于C:\Python27\Lib\distutils\distutils.ccfg,包含:[生成]编译器=mingw32

要处理MinGW不再识别-mno cygwin标志的问题,请删除C:\Python27\Lib\distutils\cygwincompiler.py第322到326行中的标志,因此如下所示:

  self.set_executables(compiler='gcc -O -Wall',
                         compiler_so='gcc -mdll -O -Wall',
                         compiler_cxx='g++ -O -Wall',
                         linker_exe='gcc',
                         linker_so='%s %s %s'
                                    % (self.linker_dll, shared_option,
                                       entry_point))

其他回答

最快的解决方案:

如果您有python3.4.x,那么解决方案就是安装VC++2010,因为它被用来将自己编译成。

https://www.visualstudio.com/en-us/downloads#d-2010年快车

我的python版本是win32上的MSC v.1600 32位(intel)]

在Windows8上运行良好

如果您希望在未安装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:)

看起来它正在寻找VC编译器,所以您可以尝试使用-c mingw32提及编译器类型,因为您有msys

python setup.py install -c mingw32

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

我尝试了许多解决方案,但只有一个对我有效,那就是安装Microsoft Visual Studio 2008 Express C++。

我使用C语言编写的Python2.7模块(yEnc,它与MSVS有其他问题)遇到了这个问题。请注意,Python 2.7是用MS VS 2008版本构建的,而不是2010!

尽管它是免费的,但很难找到,因为MS正在推广VS 2010。尽管如此,MSDN官方非常直接的链接仍然有效:检查https://stackoverflow.com/a/15319069/2227298下载链接。