Windows 上的 python pip - 命令“cl.exe”失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41724445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 01:31:12  来源:igfitidea点击:

python pip on Windows - command 'cl.exe' failed

pythonwindowspip

提问by ashishsingal

I'm trying to install spaCy using pip install spacybut I'm getting the following error ..

我正在尝试使用安装 spaCy,pip install spacy但出现以下错误..

enter image description here

在此处输入图片说明

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)]

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 库时更普遍的问题。

回答by PurkkaKoodari

You need to have cl.exe(the Microsoft C Compiler) installed on your computer and in your PATH. PATHis an environment variable that tells Windows where to find executable files.

您需要cl.exe在您的计算机和PATH. PATH是一个环境变量,它告诉 Windows 在哪里可以找到可执行文件。

First, ensure the C++ build toolsfor Visual Studio are installed. You can download Build Tools for Visual Studioseparately from the Visual Studio downloads page, then choose C++ build toolsfrom the installer. If you already have Visual Studio, you can also install Desktop development with C++from the Visual Studio Installer which you should have in Start Menu.

首先,确保安装了 Visual Studio的C++ 构建工具。您可以下载生成工具为Visual Studio从单独的Visual Studio下载页面,然后选择C ++的编译工具的安装程序。如果你已经有了 Visual Studio,你也可以从 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. For 32-bit Python, you're probably looking for x86 Native Tools Command Prompt. This sets up PATHautomatically, so that cl.execan be found.

然后,使用“开始”菜单中 Visual Studio 文件夹中的特殊命令提示符之一,而不是普通的命令提示符或 PowerShell 。对于 32 位 Python,您可能正在寻找x86 Native Tools Command Prompt。这会PATH自动设置,以便cl.exe可以找到。

回答by Kunal Mathur

This is easily the simplest solution. For those who don't know how to do this:

这很容易成为最简单的解决方案。对于那些不知道如何做到这一点的人:

  1. Install the C++ compiler https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019

  2. Go to the installation folder (In my case it is): C:\Program Files (x86)\Microsoft Visual C++ Build Tools

  3. Open Visual C++ 2015 x86 x64 Cross Build Tools Command Prompt

  4. Type: pip install package_name

  1. 安装 C++ 编译器 https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019

  2. 转到安装文件夹(在我的情况下是):C:\Program Files (x86)\Microsoft Visual C++ Build Tools

  3. 打开 Visual C++ 2015 x86 x64 交叉构建工具命令提示符

  4. 类型: pip install package_name

回答by Sebastian Cardona Osorio

In my case I need to install more tools from Visual Studio (I'm using VS 2017 Community and Python 3.6.4). I installed those tools (see installer screenshot here):

就我而言,我需要从 Visual Studio 安装更多工具(我使用的是 VS 2017 Community 和 Python 3.6.4)。我安装了这些工具(请参阅此处的安装程序屏幕截图):

  1. Desktop development with C++:I included all defaulted items and the next ones:

    • Windows XP support for C++
    • Support for C++/CLI
    • VC++ 2015.3 v140 toolset
  2. Linux development with C++

  1. 使用 C++ 进行桌面开发:我包含了所有默认项和以下项:

    • Windows XP 对 C++ 的支持
    • 支持 C++/CLI
    • VC++ 2015.3 v140 工具集
  2. 使用 C++ 进行 Linux 开发

Then I opened the Windows PowerShellas 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.

我希望它也能帮助某人。

回答by SEDaradji

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 安装下编译的包都有效。

回答by Yufang

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. for example:

在输入:pip install package_name 之前,需要将目录更改为pip.exe所在的文件夹。例如:

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'

回答by DIPENDRA YADAV

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 中运行命令,它对我有用。

回答by dragon788

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\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\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 installcommands will work best if you reboot first.

一旦你安装了这个,你应该重新启动。我偶尔会在没有重新启动的情况下工作,但是pip install如果您先重新启动,您的命令将发挥最佳效果。

Now you can pip install pipenvor pip install complex-packageand should be good to go.

现在你可以pip install pipenv或者pip install complex-package应该可以开始了。

回答by Vipin

I had come across this problem many times. There is cl.exebut for some strange reason pipcouldn't find it, even if we run the command from the binfolder where cl.exeis present. Try using conda installer, it worked fine for me.

我多次遇到过这个问题。有cl.exe,但由于一些奇怪的原因,pip找不到它,即使我们从运行的命令bin,其中文件夹cl.exe是存在的。尝试使用 conda 安装程序,它对我来说很好用。

As you can see in the following image, pipis not able to find the cl.exe. Then I tried installing using conda

如下图所示,pip无法找到cl.exe. 然后我尝试使用 conda 安装

image 1

图 1

And to my surprise it gets installed without an error once you have the right version of vs cpp build tools installed, i.e. v14.0 in the right directory.

令我惊讶的是,一旦您安装了正确版本的 vs cpp 构建工具,即正确目录中的 v14.0,它就会安装而不会出错。

image 2

图 2

回答by Harini

  1. Install Microsoft visual c++ 14.0 build tool.(Windows 7)
  2. create a virtual environment using conda.
  3. Activate the environment and use conda to install the necessary package.
  1. 安装 Microsoft Visual c++ 14.0 构建工具。(Windows 7)
  2. 使用 conda 创建虚拟环境。
  3. 激活环境并使用 conda 安装必要的包。

For example: conda install -c conda-forge spacy

例如: conda install -c conda-forge spacy