Reputation: 2978
I'm trying to install spaCy using pip install spacy
but I'm getting the following error ..
I have VS 2015 installed, and I have the following Python install ..
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 ..
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.
Upvotes: 58
Views: 150595
Reputation: 6809
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.
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.
Upvotes: 65
Reputation: 31
I was facing the same problem with 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
.
just set the environment variable as the able address and run the command in anaconda, it worked for me.
Upvotes: 3
Reputation: 3911
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.
This command is taken from 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:
Import-Module "$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1" ; Update-SessionEnvironment
Now you can use Chocolatey to install Python (latest version of 3.x is default).
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.
Now you can pip install pipenv
or pip install complex-package
and should be good to go.
Upvotes: 3
Reputation: 273
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
Go to the installation folder (In my case it is): C:\Program Files (x86)\Microsoft Visual C++ Build Tools
Open Visual C++ 2015 x86 x64 Cross Build Tools Command Prompt
Type: pip install package_name
Upvotes: 27
Reputation: 33
For example: conda install -c conda-forge spacy
Upvotes: 1
Reputation: 99
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. Try using conda installer, it worked fine for me.
As you can see in the following image, pip
is not able to find the cl.exe
. Then I tried installing using conda
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.
Upvotes: 1
Reputation: 485
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):
Desktop development with C++: I included all defaulted items and the next ones:
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]\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 install mayavi
I hope that it helps someone too.
Upvotes: 13
Reputation:
Refer to this link:
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 )
use pip to install the package, assuming that the file is in downloads folder and you have python 3.6 32 bit :
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.
Upvotes: 5
Reputation: 103
Just added to the answer from Kunal Mathur and an answer to @mockash, since I cannot comment due to lack of reputation.
Before you type: pip install package_name, you need to change the directory to the folder where pip.exe is. 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
But the weird thing is I can only successfully install via 'Visual C++ 2015 x64 x86' not 'x86 x64'
Upvotes: 4