[英]python pip on Windows - command 'cl.exe' failed
I'm trying to install spaCy using pip install spacy
but I'm getting the following error ..我正在尝试使用pip install spacy
安装 spaCy,但出现以下错误..
I have VS 2015 installed, and I have the following Python install ..我安装了 VS 2015,并且安装了以下 Python ..
3.5.2 |Anaconda 2.5.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]
I tried the following SO solutions to no avail ..我尝试了以下 SO 解决方案无济于事..
As well as various others.以及其他各种。 This is not a unique problem to this specific library but more generally anytime I try to install Python libraries that need C to build on Windows.对于这个特定的库来说,这不是一个独特的问题,但更普遍的是,每当我尝试安装需要 C 在 Windows 上构建的 Python 库时。
You are installing a package with parts written in C/C++, so you need to have cl.exe
(the Microsoft C Compiler) installed on your computer and in your PATH
.您正在安装一个包含用 C/C++ 编写的部分的包,因此您需要在您的计算机和PATH
安装cl.exe
(Microsoft C 编译器)。 PATH
is an environment variable that tells Windows where to find executable files. PATH
是一个环境变量,它告诉 Windows 在哪里可以找到可执行文件。
First, ensure the C++ build tools for Visual Studio are installed.首先,确保安装了 Visual Studio 的C++ 构建工具。
Then, instead of the normal Command Prompt or PowerShell, use one of the special command prompts in the Visual Studio folder in Start Menu .然后,使用“开始”菜单中 Visual Studio 文件夹中的特殊命令提示符之一,而不是普通的命令提示符或 PowerShell。 This sets up PATH
automatically, so that cl.exe
can be found.这会自动设置PATH
,以便可以找到cl.exe
。
This is easily the simplest solution.这很容易成为最简单的解决方案。 For those who don't know how to do this:对于那些不知道如何做到这一点的人:
Install the C++ compiler https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019安装 C++ 编译器https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
Go to the installation folder (In my case it is): C:\\Program Files (x86)\\Microsoft Visual C++ Build Tools转到安装文件夹(在我的情况下是):C:\\Program Files (x86)\\Microsoft Visual C++ Build Tools
Open Visual C++ 2015 x86 x64 Cross Build Tools Command Prompt打开 Visual C++ 2015 x86 x64 交叉构建工具命令提示符
Type: pip install package_name
类型: pip install package_name
In my case I need to install more tools from Visual Studio (I'm using VS 2017 Community and Python 3.6.4).就我而言,我需要从 Visual Studio 安装更多工具(我使用的是 VS 2017 Community 和 Python 3.6.4)。 I installed those tools (see installer screenshot here ):我安装了这些工具(请参阅此处的安装程序屏幕截图):
Desktop development with C++: I included all defaulted items and the next ones:使用 C++ 进行桌面开发:我包含了所有默认项和以下项:
Linux development with C++使用 C++ 进行 Linux 开发
Then I opened the Windows PowerShell as Administrator privilegies (Right click to open) and move folder of Visual Studio installation and find that path:然后我以管理员权限打开Windows PowerShell (右键单击打开)并移动 Visual Studio 安装文件夹并找到该路径:
cd [Visual Studio Path]\VC\Auxiliary\Build
Then I executed this file:然后我执行了这个文件:
.\vcvars32.bat
After that I use pip as normal, for instance, I wanted to install Mayavi :之后我像往常一样使用 pip ,例如,我想安装Mayavi :
pip install mayavi
I hope that it helps someone too.我希望它也能帮助某人。
Refer to this link:参考这个链接:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#cytoolz https://www.lfd.uci.edu/~gohlke/pythonlibs/#cytoolz
Download the right whl package for you python version(if you have trouble knowing what version of python you have, just lunch the interpreter )为您的python 版本下载正确的whl 包(如果您不知道自己拥有哪个版本的python,请与解释器共进午餐)
use pip to install the package, assuming that the file is in downloads folder and you have python 3.6 32 bit :使用 pip 安装包,假设文件在下载文件夹中并且你有 python 3.6 32 位:
python -m pip install C:\\Users\\%USER%\\Downloads\\cytoolz‑0.9.0.1‑cp36‑cp36m‑win32.whl python -m pip install C:\\Users\\%USER%\\Downloads\\cytoolz‑0.9.0.1‑cp36‑cp36m‑win32.whl
this is not valid for just this package, but for any package that cannot compile under your own windows installation.这不仅对这个包有效,而且对任何不能在你自己的 Windows 安装下编译的包都有效。
Just added to the answer from Kunal Mathur and an answer to @mockash, since I cannot comment due to lack of reputation.刚刚添加到 Kunal Mathur 的答案和 @mockash 的答案,因为由于缺乏声誉,我无法发表评论。
Before you type: pip install package_name, you need to change the directory to the folder where pip.exe is.在输入:pip install package_name 之前,需要将目录更改为pip.exe所在的文件夹。 for example:例如:
Open Visual C++ 2015 x86 x64 Cross Build Tools Command Prompt--> change directory cd C:\\Users\\Test\\AppData\\Local\\Programs\\Python\\Python36-32\\Scripts-->Type: pip install package_name打开Visual C++ 2015 x86 x64 Cross Build Tools Command Prompt-->更改目录cd C:\\Users\\Test\\AppData\\Local\\Programs\\Python\\Python36-32\\Scripts-->输入:pip install package_name
But the weird thing is I can only successfully install via 'Visual C++ 2015 x64 x86' not 'x86 x64'
但奇怪的是我只能通过'Visual C++ 2015 x64 x86' not 'x86 x64'
成功安装
I was facing the same problem with visual studio 2017.我在 Visual Studio 2017 中遇到了同样的问题。
you can find cl.exe in C:\\Program Files(x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\Hostx86\\x86
.您可以在C:\\Program Files(x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\Hostx86\\x86
找到 cl.exe。
just set the environment variable as the able address and run the command in anaconda, it worked for me.只需将环境变量设置为可用地址并在 anaconda 中运行命令,它对我有用。
I had come across this problem many times.我多次遇到过这个问题。 There is cl.exe
but for some strange reason pip
couldn't find it, even if we run the command from the bin
folder where cl.exe
is present.有cl.exe
但由于某些奇怪的原因pip
找不到它,即使我们从cl.exe
所在的bin
文件夹运行命令。 Try using conda installer, it worked fine for me.尝试使用 conda 安装程序,它对我来说很好用。
As you can see in the following image, pip
is not able to find the cl.exe
.如下图所示, pip
无法找到cl.exe
。 Then I tried installing using conda然后我尝试使用 conda 安装
And to my surprise it gets installed without an error once you have the right version of vs cpp build tools installed, ie v14.0 in the right directory.令我惊讶的是,一旦您安装了正确版本的 vs cpp 构建工具,即正确目录中的 v14.0,它就会安装而不会出错。
For example: conda install -c conda-forge spacy例如: conda install -c conda-forge spacy
If you want it really easy and a joy to automate, check out Chocolatey.org/install and you can basically copy and paste these commands and tweak it based on what versions of VC++ you need.如果你想要它真的很容易和自动化,请查看 Chocolatey.org/install,你基本上可以复制和粘贴这些命令,并根据你需要的 VC++ 版本进行调整。
This command is taken from https://chocolatey.org/install此命令取自https://chocolatey.org/install
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Once you have chocolatey installed you can either close and reopen your Powershell terminal or run this command:安装 Chocolatey 后,您可以关闭并重新打开 Powershell 终端或运行以下命令:
Import-Module "$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1" ; Update-SessionEnvironment
Now you can use Chocolatey to install Python (latest version of 3.x is default).现在您可以使用 Chocolatey 来安装 Python(默认为最新版本的 3.x)。
choco install python
# This next command installs the latest VisualStudio installer that lets you get specific versions of the build
# Microsoft has replaced the 2015 and 2017 installer links with this one, and we can still use it to install the 2015 and 2017 components
choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.140 --passive --locale en-US --add Microsoft.VisualStudio.Component.Windows10SDK.$($PSVersionTable.BuildVersion.Build) --no-includeRecommended" -y --timeout 0
# Usually need the "unlimited" timeout aka "0" because Visual Studio Installer takes forever
# Tool portion
# Microsoft.VisualStudio.Product.BuildTools
# Component portion(s)
# Microsoft.VisualStudio.Component.VC.140
# Win10SDK needs to match your current Win10 build version
# $($PSVersionTable.BuildVersion.Build)
# Microsoft.VisualStudio.Component.Windows10SDK.$($PSVersionTable.BuildVersion.Build)
# Because VS2019 Build Tools are dumb, need to manually link a couple files between the SDK and the VC++ dirs
# You may need to tweak the version here, but it has been updated to be as dynamic as possible
# Use an elevated Powershell or elevated cmd prompt (if using cmd.exe just use the bits after /c)
cmd /c mklink "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\rc.exe" "C:\Program Files (x86)\Windows Kits\10\bin\$($PSVersionTable.BuildVersion.Major).$($PSVersionTable.BuildVersion.Minor).$($PSVersionTable.BuildVersion.Build).0\x64\rc.exe"
cmd /c mklink "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\rcdll.dll" "C:\Program Files (x86)\Windows Kits\10\bin\$($PSVersionTable.BuildVersion.Major).$($PSVersionTable.BuildVersion.Minor).$($PSVersionTable.BuildVersion.Build).0\x64\rcdll.dll"
Once you have this installed, you should reboot.一旦你安装了这个,你应该重新启动。 I've occasionally had things work without a reboot, but your pip install
commands will work best if you reboot first.我偶尔会在没有重新启动的情况下工作,但是如果您先重新启动,您的pip install
命令将工作得最好。
Now you can pip install pipenv
or pip install complex-package
and should be good to go.现在您可以pip install pipenv
或pip install complex-package
并且应该很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.