我已经安装了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包

其他回答

我也有同样的问题。下载Visual Studio 2017的构建工具对我有用。

使用Visual c++ 2015 Build Tools的链接。这将安装Visual c++ 14.0而不安装Visual Studio。

我也有同样的问题。我需要一个64位版本的Python,所以我安装了3.5.0(撰写本文时最新的版本)。切换到3.4.3之后,我的所有模块安装都正常了。

Python Windows版本

在为Django项目安装mysqlclient时,我也遇到了同样的问题。

在我的例子中,是系统架构不匹配导致了这个问题。我的系统上有Windows 7 64位版本。但是,我错误地安装了Python 3.7.2 32位版本。

所以,我重新安装Python解释器(64位)并运行命令

pip install mysqlclient

我希望这也适用于其他Python包。

使用此链接下载并安装Visual c++ 2015 Build Tools。它将自动下载visualcppbuildtools_full.exe并安装Visual c++ 14.0,而无需实际安装Visual Studio。

安装完成后,重试pip install,您将不会再次得到错误。

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

Python 3.6 on Windows 7 64-bit
Python 3.8 on Windows 10 64-bit