我已经安装了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正确安装模块。


当前回答

要扩展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工具工作。

其他回答

只要去https://www.lfd.uci.edu/~gohlke/pythonlibs/找到适合你的包(whl文件)。下载它。在cmd中进入下载文件夹,或者在文件夹的地址栏上输入'cmd'。执行如下命令:

pip install mysqlclient-1.4.6-cp38-cp38-win32.whl

(请正确输入文件名。我只是举了一个例子)。无需安装6GB大小的build toll cpp,您的问题将得到解决。

我在安装mayavi时遇到了这个问题。

我还犯了一个常见错误:在pip安装库时需要Microsoft Visual c++ 14.0。

在浏览了许多网页和这个问题的解决方案后,没有一个可行,我想出了这些步骤(大部分取自以前的解决方案)可以让这个问题起作用。

Go to Build Tools for Visual Studio 2017 and install Build Tools for Visual Studio 2017. Which is under All downloads (scroll down) → Tools for Visual Studio 2017 If you have already installed this, skip to 2. Select the C++ components you require (I didn't know which I required, so I installed many of them). If you have already installed Build Tools for Visual Studio 2017 then open the application Visual Studio Installer then go to Visual Studio Build Tools 2017 → Modify → Individual Components and selected the required components. From other answers, important components appear to be: C++/CLI support, VC++ 2017 version <...> latest, Visual C++ 2017 Redistributable Update, Visual C++ tools for CMake, Windows 10 SDK <...> for Desktop C++, Visual C++ Build Tools core features, Visual Studio C++ core features. Install/Modify these components for Visual Studio Build Tools 2017. This is the important step. Open the application Visual Studio Installer then go to Visual Studio Build Tools → Launch. Which will open a CMD window at the correct location for Microsoft Visual Studio\YYYY\BuildTools. Now enter python -m pip install --upgrade setuptools within this CMD window. Finally, in this same CMD window, pip install your Python library: pip install -U <library>.

首先,你需要从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包

哦!看起来他们在PyPI上没有Windows轮子。

与此同时,从源代码安装可能是有效的,或者尝试下载msvc++ 14,根据错误消息和本页其他人的建议。

Christoph的网站也有非官方的Python扩展包的Windows二进制文件(。whl文件)。

按照以下链接中提到的步骤安装二进制文件:

直接在基本Python中 在虚拟环境和PyCharm

也检查:

文件名。本平台不支持WHL轮

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

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

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

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