I tried to install the Python package dulwich:
pip install dulwich
But I get a cryptic error message:
error: Unable to find vcvarsall.bat
The same happens if I try installing the package manually:
> python setup.py install
running build_ext
building 'dulwich._objects' extension
error: Unable to find vcvarsall.bat
What's going on? Python modules can be part written in C or C++ (typically for speed). If you try to install such a package with Pip (or
setup.py
), it has to compile that C/C++ from source. Out the box, Pip will brazenly assume you the compiler Microsoft Visual C++ installed. If you don't have it, you'll see this cryptic error message "Error: Unable to find vcvarsall.bat".The prescribed solution is to install a C/C++ compiler, either Microsoft Visual C++, or MinGW (an open-source project). However, installing and configuring either is prohibitively difficult. (Edit 2014: Microsoft have published a special C++ compiler for Python 2.7)
The easiest solution is to use Christoph Gohlke's Windows installers (.msi) for popular Python packages. He builds installers for Python 2.x and 3.x, 32 bit and 64 bit. You can download them from http://www.lfd.uci.edu/~gohlke/pythonlibs/
If you too think "Error: Unable to find vcvarsall.bat" is a ludicrously cryptic and unhelpful message, then please comment on the bug at http://bugs.python.org/issue2943 to replace it with a more helpful and user-friendly message.
For comparison, Ruby ships with a package manager Gem and offers a quasi-official C/C++ compiler, DevKit. If you try to install a package without it, you see this helpful friendly useful message:
You can read a longer rant about Python packaging at https://stackoverflow.com/a/13445719/284795
You can install compiled version from http://www.lfd.uci.edu/~gohlke/pythonlibs/
I spent almost 2 days figuring out how to fix this problem in my python 3.4 64 bit version: Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Solution 1, hard: (before reading this, read first Solution 2 below) Finally, this is what helped me:
vcvars64.bat
inC:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64
which containsCALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
or other path depending on where you have yours installedafter that I tried to
pip install numpy
but received the following error:I changed
mfinfo
toNone
inC:\Python34\Lib\distutils\msvc9compiler.py
per this https://stackoverflow.com/a/23099820/4383472pip install numpy
command my avast antivirus tried to interfere into the installation process, but i quickly disabled itIt took very long - several minutes for numpy to compile, I even thought that there was an error, but finally everything was ok.
Solution 2, easy: (I know this approach has already been mentioned in a highly voted answer, but let me repeat since it really is easier) After going through all of this work I understood that the best way for me is just to use already precompiled binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/ in future. There is very small chance that I will ever need some package (or a version of a package) which this site doesn't contain. The installation process is also much quicker this way. For example, to install
numpy
:numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl
(if you have Python 3.4 64-bit) from that sitepip install numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl
(or full path to the file depending how command prompt is opened)I had this problem using Python 3.4.1 on Windows 7 x64, and unfortunately the packages I needed didn't have suitable exe or wheels that I could use. This system requires a few 'workarounds', which are detailed below (and TLDR at bottom).
Using the info in Jaxrtech's answer above, I determined I needed Visual Studio C++ 2010 (sys.version return MSC v.1600), so I installed Visual C++ 2010 Express from the link in his answer, which is http://go.microsoft.com/?linkid=9709949. I installed everything with updates, but as you can read below, this was a mistake. Only the original version of Express should be installed at this time (no updated anything).
vcvarsall.bat was now present, but there was a new error when installing the package,
query_vcvarsall raise ValueError(str(list(result.keys())))ValueError: [u'path']
. There are other stackoverflow questions with this error, such as Errors while building/installing C module for Python 2.7I determined from that answer that 2010 Express only installs 32-bit compilers. To get 64-bit (and other) compilers, you need to install Windows 7.1 SDK. See http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx
This would not install for me though, and the installer returned the error
installation failed with return code 5100
. I found the solution at the following link: http://support.microsoft.com/kb/2717426. In short, if newer versions of x86 and x64 Microsoft Visual C++ 2010 Redistributable's are installed, they conflict with the ones in SDK installer, and need uninstalling first.The SDK then installed, but I noticed vcvars64.bat still did not exist in
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin
, nor its subfolders. vcvarsall.bat runs the vcvars64 batch file, so without it, the python package still wouldn't install (I forgot the error that was shown at this time).I then found some instructions here: http://www.cryptohaze.com/wiki/index.php/Windows_7_Build_Setup#Download_VS_2010_and_Windows_SDK_7.1 Following the instructions, I had already installed Express and 7.1 SDK, so installed SDK 7.1 SP1, and did the missing header file fix. I then manually created vcvars64.bat with the content
CALL setenv /x64
. I will paste all those instructions here, so they don't get lost.My python package still did not install (can't recall error). I then found some instructions (copied below) to use the special SDK 7.1 Command Prompt, see: https://mail.python.org/pipermail/distutils-sig/2012-February/018300.html
I opened the Windows SDK 7.1 Command Prompt as instructed, and used it to run easy_install on the python package. And at last, success!
TLDR;
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat
with contentCALL setenv /x64
Update: Comments point out that the instructions here may be dangerous. Consider using the Visual C++ 2008 Express edition or the purpose-built Microsoft Visual C++ Compiler for Python (details) and NOT using the original answer below. Original error message means the required version of Visual C++ is not installed.
For Windows installations:
While running setup.py for package installations, Python 2.7 searches for an installed Visual Studio 2008. You can trick Python to use a newer Visual Studio by setting the correct path in
VS90COMNTOOLS
environment variable before callingsetup.py
.Execute the following command based on the version of Visual Studio installed:
SET VS90COMNTOOLS=%VS100COMNTOOLS%
SET VS90COMNTOOLS=%VS110COMNTOOLS%
SET VS90COMNTOOLS=%VS120COMNTOOLS%
SET VS90COMNTOOLS=%VS140COMNTOOLS%
WARNING: As noted below, this answer is unlikely to work if you are trying to compile python modules.
See Building lxml for Python 2.7 on Windows for details.
I tried many solutions but only one worked for me, the install of Microsoft Visual Studio 2008 Express C++.
I got this issue with a Python 2.7 module written in C (yEnc, which has other issues with MS VS). Note that Python 2.7 is built with MS VS 2008 version, not 2010!
Despite the fact it's free, it is quite hard to find since MS is promoting VS 2010. Still, the MSDN official very direct links are still working: check https://stackoverflow.com/a/15319069/2227298 for download links.