我已经安装了Python 3.5,并且正在运行

pip install mysql-python

它给出了如下错误

错误:Microsoft Visual c++ 14.0是必需的(无法找到vcvarsall.bat)

我已经添加了以下行到我的路径

C:\Program Files\Python 3.5\Scripts\;
C:\Program Files\Python 3.5\;

C:\Windows\System32;
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC;
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC

我的电脑上安装了64位的Windows 7。

什么解决方案可以减少这个错误,并通过pip正确安装模块。


当前回答

首先,你需要从https://visualstudio.microsoft.com/downloads#other下载visualstudio构建工具 重命名文件vs_buildtools.exe(不是必需的,但您必须修改下面的脚本)

start-process -wait -filepath vs_buildtools.exe -ArgumentList '--quiet --wait --norestart --nocache --installPath C:\BuildTools `
  --add Microsoft.VisualStudio.ComponentGroup.VC.Tools.142.x86.x64 `
  --add Microsoft.VisualStudio.Component.Windows10SDK.19041 `
  --add Microsoft.VisualStudio.Component.Windows10SDK `
  --add Microsoft.VisualStudio.Component.VC.CoreIde `
  --add Microsoft.VisualStudio.Component.VC.CMake.Project `
  --add Microsoft.VisualStudio.Component.VC.14.29.16.11.CLI.Support `
  --add Microsoft.VisualStudio.ComponentGroup.UWP.VC.v142'

我在这里为windows docker用户创建了一个单独的问题和答案,Microsoft Visual c++ 14.0是必需的,在windows docker上安装pip包

其他回答

以下是Windows c++编译器的官方安装指南:

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

升级setuptools并安装特定的Microsoft Visual c++编译器。

它已经包含了其他答案中提到的一些要点。

在Stack Overflow上阅读了很多答案后,没有一个可以工作,我最终设法按照这个问题中的步骤解决它。我将把步骤留在这里,以防页面消失:

请尝试安装Visual Studio 2017的构建工具,选择工作负载“Visual c++构建工具”,并检查选项“c++ /CLI支持”和“vc++ 2015.3 v14.00 (v140)桌面工具集”,如下所示。

要扩展ocean800、davidsheldon和user3661384的答案:

你现在应该不再使用Visual Studio Tools 2015,因为有一个更新的版本可用。正如Python文档所指出的,您应该使用Visual Studio Tools 2017。

Visual c++ Build Tools 2015由微软升级为Visual Studio Build Tools 2017。

从这里下载。

您还需要setuptools。如果你没有安装工具,运行:

pip install setuptools

或者如果你已经有了,一定要升级它。

pip install setuptools --upgrade

对于上面的Python文档链接,您将看到setuptools版本必须至少为34.4.0才能使Visual Studio工具工作。

二进制安装它的简单方法!

使用pip的二进制选项。例如,对于mysqlclient:

pip install --only-binary :all: mysqlclient

许多包不会为每个单独的版本创建一个构建,这迫使您的pip从源代码构建。如果您乐于使用最新的预编译二进制版本,请使用——only-binary:all:允许pip使用较旧的二进制版本。

首先,你需要从https://visualstudio.microsoft.com/downloads#other下载visualstudio构建工具 重命名文件vs_buildtools.exe(不是必需的,但您必须修改下面的脚本)

start-process -wait -filepath vs_buildtools.exe -ArgumentList '--quiet --wait --norestart --nocache --installPath C:\BuildTools `
  --add Microsoft.VisualStudio.ComponentGroup.VC.Tools.142.x86.x64 `
  --add Microsoft.VisualStudio.Component.Windows10SDK.19041 `
  --add Microsoft.VisualStudio.Component.Windows10SDK `
  --add Microsoft.VisualStudio.Component.VC.CoreIde `
  --add Microsoft.VisualStudio.Component.VC.CMake.Project `
  --add Microsoft.VisualStudio.Component.VC.14.29.16.11.CLI.Support `
  --add Microsoft.VisualStudio.ComponentGroup.UWP.VC.v142'

我在这里为windows docker用户创建了一个单独的问题和答案,Microsoft Visual c++ 14.0是必需的,在windows docker上安装pip包