python pip on Windows – command cl.exe failed

python pip on Windows – command cl.exe failed

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. PATH is an environment variable that tells Windows where to find executable files.

First, ensure the C++ build tools for Visual Studio are installed.

  • If you already have Visual Studio on your computer, install Desktop development with C++ from the Visual Studio Installer, which you should have in Start Menu.
  • Otherwise, you can download Build Tools for Visual Studio separately from the Visual Studio downloads page (near the bottom of the page), then choose C++ build tools from the installer.

Then, instead of the normal Command Prompt or PowerShell, use one of the special command prompts in the Visual Studio folder in Start Menu. This sets up PATH automatically, so that cl.exe can be found.

  • For 32-bit Python, use x86 Native Tools Command Prompt.
  • For 64-bit Python, use x64 Native Tools Command Prompt.

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

  1. Install the C++ compiler

  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

python pip on Windows – command cl.exe failed

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

  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++

Then I opened the Windows PowerShell as Administrator privilegies (Right click to open) and move folder of Visual Studio installation and find that path:

cd [Visual Studio Path]VCAuxiliaryBuild

Then I executed this file:


After that I use pip as normal, for instance, I wanted to install Mayavi:

pip install mayavi

I hope that it helps someone too.

Leave a Reply

Your email address will not be published. Required fields are marked *