python "python - error:Unable to find vcvarsall.bat
egg_info" command (25)
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
You can install compiled version from http://www.lfd.uci.edu/~gohlke/pythonlibs/
I found the solution. I had the exact same problem, and error, installing 'amara'. I had mingw32 installed, but distutils needed to be configured.
- I have Python 2.6 that was already installed.
- I installed mingw32 to
- Add mingw32's bin directory to your environment variable: append
c:\programs\MinGW\bin;to the PATH
Edit (create if not existing) distutils.cfg file located at
Make sure environment is set by opening a new
I had the same error (which I find silly and not really helpful whatsoever as error messages go) and continued having problems, despite having a C compiler available.
Surprising, what ended up working for me was simply upgrading pip and setuptools to the most recent version. Hope this helps someone else out there.
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:
Please update your PATH to include build tools or download the DevKit from http://rubyinstaller.org/downloads and follow the instructions at http://github.com/oneclick/rubyinstaller/wiki/Development-Kit
You can read a longer rant about Python packaging at https://.com/a/13445719/284795
If you're looking to install pyodbc on a Windows box that doesn't have Visual Studio installed another option is to manually install pyodbc using the binary distribution.
This is particularly useful if you do not have administrator privileges on the machine you're working with and are trying to set up a virtualenv.
- Download the latest Windows installer from here (pyodbc-X.X.X.win-Y-py2.7.exe)
- Open the installer executable using 7-Zip (or WinRAR or whatever)
- Extract pyodbc.pyd and pyodbc-X.X.X-py2.7.egg-info and place them in
[python installation directory or virtualenv]\Lib\site-packages
- There is no step 4 :)
I just had this same problem, so I'll tell my story here hoping it helps someone else with the same issues and save them the couple of hours I just spent:
I have mingw (g++ (GCC) 4.6.1) and python 2.7.3 in a windows 7 box and I'm trying to install PyCrypto.
It all started with this error when running setup.py install:
error: Unable to find vcvarsall.bat
Easily solved after googling the error by specifying mingw as the compiler of choice:
setup.py install build --compiler=mingw32
The problem is that then I got a different error:
configure: error: cannot run C compiled programs.
It turns out that my anti-virus was blocking the execution of a freshly compiled .exe. I just disabled the anti-virus "resident shield" and went to the next error:
cc1.exe: error: unrecognized command line option '-mno-cygwin' error: command 'gcc' failed with exit status 1
This solved it: "Either install a slightly older version of MinGW, or edit distutils\cygwinccompiler.py in your Python directory to remove all instances of -mno-cygwin." (from here)
Now, I can finally start working.
If you have mingw installed
pip install --global-option build_ext --global-option --compiler=mingw32 packagename
works, forcing pip to build using the mingw compiler instead of Microsoft's. See here https://github.com/pypa/pip/issues/18 for details (last post).
I don't know if it is too late, but I found Microsoft Visual C++ Compiler for Python 2.7 which reads
The typical error message you will receive if you need this compiler package is Unable to find vcvarsall.bat
Hope this helps!
Below steps fixed this issue for me, I was trying to create setup with cython extension.
- Install Microsoft Visual C++ Compiler for Python 2.7
- The default install location would be @ C:\Users\PC-user\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python This might actually fix the issue, test once before proceeding.
- If it fails, Check where in VC++ for python vcvarsall.bat file is located
- Open the msvc9compiler.py file of distutils package in notepad.
- In my box this was @ C:\Anaconda2\Lib\distutils\msvc9compiler.py find_vcvarsall function in this file, determine the version of VC by printing out version argument. For Python 2.7 it's likely to be 9.0
- Now create an environment variable VS90COMNTOOLS, Pointing to C:\Users\PC-user\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\bin
For some reason distutils expects the vcvarsall.bat file to be within VC dir, but VC++ for python tools has it in the root of 9.0 To fix this, remove "VC" from the path.join (roughly around line 247)
#productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") productdir = os.path.join(toolsdir, os.pardir, os.pardir)
The above steps fixed the issue for me.
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://.com/a/15319069/2227298 for download links.
With Python 3.4, the dependency is on Visual Studio 2010. Installing Visual C++ 2010 Express fixed the problem for me.
Tricking it into using the VS 2008 or 2013 installs that I happened to have didn't work.
Is Microsoft Visual C++ Compiler for Python 2.7 at http://www.microsoft.com/en-us/download/details.aspx?id=44266 not a solution?
You can download the free Visual C++ 2008 Express Edition from http://go.microsoft.com/?linkid=7729279, which will set the VS90COMNTOOLS environment variable during installation and therefore build with a compatible compiler.
As @PiotrDobrogost mentioned in a comment, his answer to this other question goes into details about why Visual C++ 2008 is the right thing to build with, but this can change as the Windows build of Python moves to newer versions of Visual Studio: Building lxml for Python 2.7 on Windows
I have python 2.73 and windows 7 .The solution that worked for me was:
- Added mingw32's bin directory to environment variable: append PATH with
Created distutils.cfg located at
To deal with MinGW not recognizing the -mno-cygwin flag anymore, remove the flag in C:\Python27\Lib\distutils\cygwincompiler.py line 322 to 326, so it looks like this:
self.set_executables(compiler='gcc -O -Wall', compiler_so='gcc -mdll -O -Wall', compiler_cxx='g++ -O -Wall', linker_exe='gcc', linker_so='%s %s %s' % (self.linker_dll, shared_option, entry_point))
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 calling
Execute the following command based on the version of Visual Studio installed:
- Visual Studio 2010 (VS10):
- Visual Studio 2012 (VS11):
- Visual Studio 2013 (VS12):
- Visual Studio 2015 (VS14):
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.
If you have python 3.4.x, the solution is simply to install VC++ 2010 since it is used to compile itself into.
my python version is MSC v.1600 32 bit (intel)] on win32
worked fine on Windows8
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:
- install Visual C++ 2010 Express
- install Microsoft Windows SDK v7.1 for Windows 7
- create manually file
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64which contains
CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64or other path depending on where you have yours installed
- (this seems to be optional) install Microsoft Visual Studio 2010 Service Pack 1 together with Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1
after that I tried to
pip install numpybut received the following error:
File "numpy\core\setup.py", line 686, in get_mathlib_info raise RuntimeError("Broken toolchain: cannot link a simple C program") RuntimeError: Broken toolchain: cannot link a simple C program
C:\Python34\Lib\distutils\msvc9compiler.pyper this https://.com/a/23099820/4383472
- finally after
pip install numpycommand my avast antivirus tried to interfere into the installation process, but i quickly disabled it
It 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‑1.9.2+mkl‑cp34‑none‑win_amd64.whl(if you have Python 3.4 64-bit) from that site
- in command prompt or powershell install it with pip
pip install numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl(or full path to the file depending how command prompt is opened)
You can use easy_install instead of pip it works for me.
If you want to compile with Visual Studio C++ instead of mingw...
python.exeto display which version of VC++ it was compiled with (example shown below).
- Yellow (top) is Python 2.7, compiled with MSC v.1500 (Visual Studio C++ 2008)
- Red (bottom) is Python 3.4.1, compiled with MSC v.1600 (Visual Studio C++ 2010)
Use the table below to match the internal VC++ version with the corresponding Visual Studio release:
MSC v.1000 -> Visual C++ 4.x MSC v.1100 -> Visual C++ 5 MSC v.1200 -> Visual C++ 6 MSC v.1300 -> Visual C++ .NET MSC v.1310 -> Visual C++ .NET 2003 MSC v.1400 -> Visual C++ 2005 (8.0) MSC v.1500 -> Visual C++ 2008 (9.0) MSC v.1600 -> Visual C++ 2010 (10.0) MSC v.1700 -> Visual C++ 2012 (11.0) MSC v.1800 -> Visual C++ 2013 (12.0) MSC v.1900 -> Visual C++ 2015 (14.0) MSC v.1910 -> Visual C++ 2017 (15.0)
Download and install the corresponding version of Visual Studio C++ from the previous step.
Additional notes for specific versions of VC++ are listed below.
Notes for Visual Studio C++ 2008
For only the 32-bit compilers, download Visual Studio C++ 2008 Express Edition.
For the 64-bit compilers, download Windows SDK for Windows 7 and .NET Framework 3.5 SP1.
- Uncheck everything except
Developer Tools >> Visual C++ Compilersto save time and disk space from installing SDK tools you otherwise don't need.
Notes for Visual Studio C++ 2010
According to Microsoft, if you installed Visual Studio 2010 SP1, it may have removed the compilers and libraries for VC++.
If that is the case, download Visual C++ 2010 SP1 Compiler Update.
Notes for Visual Studio C++ 2015
If you don't need the Visual Studio IDE, download Visual Studio C++ 2015 Build Tools.
Notes for Visual Studio C++ 2017
If you don't need the Visual Studio IDE, download Build Tools for Visual Studio 2017.
Suggestion: If you have both a 32- and 64-bit Python installation, you may also want to use virtualenv to create separate Python environments so you can use one or the other at a time without messing with your path to choose which Python version to use.
- Uncheck everything except
According to @srodriguex, you may be able to skip manually loading the batch file (Steps 4-6) by instead copying a few batch files to where Python is searching by following this answer. If that doesn't work, here are the following steps that originally worked for me.
Open up a
Before you try installing something which requires C extensions, run the following batch file to load the VC++ compiler's environment into the session (i.e. environment variables, the path to the compiler, etc).
Note: 32-bit Windows installs will only have
C:\Program Files\as expected
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars64.bat"
Note: Yes, the native 64-bit compilers are in
Program Files (x86). Don't ask me why.
Additionally, if you are wondering what the difference between
vcvarsx86_amd64.bator more importantly the difference between
x86_amd64, the former are for the native 64-bit compiler tools and the latter are the 64-bit cross compilers that can run on a 32-bit Windows installation.
If for some reason you are getting
error: ... was unexpected at this time.where the
...is some series of characters, then you need to check that you path variable does not have any extraneous characters like extra quotations or stray characters. The batch file is not going to be able to update your session path if it can't make sense of it in the first place.
If that went well, you should get one of the following messages depending on which version of VC++ and which command you ran:
For the 32-bit compiler tools:
Setting environment for using Microsoft Visual Studio 20xx x86 tools.
For the 64-bit compiler tools:
Setting environment for using Microsoft Visual Studio 20xx x64 tools.
Now, run the setup via
python setup.py installor
pip install pkg-name
Hope and cross your fingers that the planets are aligned correctly for VC++ to cooperate.
Look in the
setup.py file of the package you are trying to install. If it is an older package it may be importing
distutils.core.setup() rather than
I ran in to this (in 2015) with a combination of these factors:
The Microsoft Visual C++ Compiler for Python 2.7 from http://aka.ms/vcpython27
An older package that uses
Trying to do
python setup.py buildrather than using
If you use a recent version of pip, it will force (monkeypatch) the package to use setuptools, even if its
setup.py calls for distutils. However, if you are not using pip, and instead are just doing
python setup.py build, the build process will use
distutils.core.setup(), which does not know about the compiler install location.
Step 1: Open the appropriate Visual C++ 2008 Command Prompt
Open the Start menu or Start screen, and search for "Visual C++ 2008 32-bit Command Prompt" (if your python is 32-bit) or "Visual C++ 2008 64-bit Command Prompt" (if your python is 64-bit). Run it. The command prompt should say Visual C++ 2008 ... in the title bar.
Step 2: Set environment variables
Set these environment variables in the command prompt you just opened.
SET DISTUTILS_USE_SDK=1 SET MSSdk=1
Step 3: Build and install
cd to the package you want to build, and run
python setup.py build, then
python setup.py install. If you want to install in to a virtualenv, activate it before you build.
You'll need to install a Microsoft compiler, compatible with the compiler used to build Python. This means you need Visual C++ 2008 (or newer, with some tweaking).
Microsoft now supplies a bundled compiler and headers just to be able to compile Python extensions, at the memorable URL:
Microsoft Visual C++ Compiler for Python 2.7
This is a relatively small package; 85MB to download, installable without admin privileges, no reboot required. The name is a little misleading, the compiler will work for any Python version originally compiled with Visual C++ 2008, not just Python 2.7.
If you start a Python interactive prompt or print
sys.version, look for the
MSC version string; if it is
MSC v.1500 you can use this tool.
Microsoft has released a compiler package for Python 2.7 to make it easier for people to build and distribute their C extension modules on Windows. The Microsoft Visual C++ Compiler for Python 2.7 (a.k.a. VC9) is available from: http://aka.ms/vcpython27
This package contains all the tools and headers required to build C extension modules for Python 2.7 32-bit and 64-bit (note that some extension modules require 3rd party dependencies such as OpenSSL or libxml2 that are not included). Other versions of Python built with Visual C++ 2008 are also supported, so "Python 2.7" is just advertising - it'll work fine with 2.6 and 3.2.
Note that you need to have
setuptools 6.0 or newer installed (listed in the system requirements on the download page). The project you are installing must use
distutils or the auto-detection won't work.
Microsoft has stated that they want to keep the URL stable, so that automated scripts can reference it easily.
I wanted to run pysph on Windows 10 under Python 2.7 and got vcvarsall.bat was not found (from distutils)
My solution was the following:
Install Microsoft Visual C++ for Python 2.7 (like @Michael suggested)
On Windows 10 it was installed into (my username is Andreas):
C:\Users\Andreas\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
Set environment variable VS90COMNTOOLS to the installation path of Visual C++ for Python 2.7 (see above path).
If it still doesn't work, then modifiy in the module
the file msvc9compiler.py. Find in it the function find_vcvarsall and do following modification.
Replace the line:
productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
productdir = os.path.join(toolsdir)
This is where vcvarsall.bat resides in my case (check, where vcvarsall.bat is in your installation).
Looks like its looking for VC compilers, so you could try to mention compiler type with
-c mingw32, since you have msys
python setup.py install -c mingw32
The easiest way to solve this in 2016 is to install Chocolatey and then the
vcpython27 package. Open Powershell:
> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) > choco install python2 -y > choco install vcpython27 -y
I was getting the same error in python 3.4.3 too and I tried using the solutions mentioned here and elsewhere with no success.
Microsoft makes a compiler available for Python 2.7 but it didn't do me much good since I am on 3.4.3.
Python since 3.3 has transitioned over to 2010 and you can download and install Visual C++ 2010 Express for free here: https://www.visualstudio.com/downloads/download-visual-studio-vs#d-2010-express
Here is the official blog post talking about the transition to 2010 for 3.3: http://blog.python.org/2012/05/recent-windows-changes-in-python-33.html
Because previous versions gave a different error for vcvarsall.bat I would double check the version you are using with "pip -V"
C:\Users\B>pip -V pip 6.0.8 from C:\Python34\lib\site-packages (python 3.4)
As a side note, I too tried using the latest version of VC++ (2013) first but it required installing 2010 express.
From that point forward it should work for anyone using the 32 bit version, if you are on the 64 bit version you will then get the ValueError: ['path'] message because VC++ 2010 doesn't have a 64 bit compuler. For that you have to get the Microsoft SDK 7.1. I can't hyperlink the instruction for 64 bit because I am limited to 2 links per post but its at