[python] Cannot find vcvarsall.bat when running a Python script

I am working on Vista, and using Python 2.6.4. I am using a software that utilizes a Python script, but bumped into the message:

cannot find vcvarsall.bat

So, I installed visual c++ 2010. Still the file is not found - though, it is there. My guess (a very uneducated one...) is that somewhere the path is wrong, because I also have an old visual 2008 (pretty empty) folder. I have no idea where to make the changes for the new path. Do I change something in the registry or in the script? Or somewhere else?

This question is related to python visual-studio-2010

The answer is


After trying every option available on every thread, I decided to dig into the source to find a solution.

Edit your $PythonPath/Lib/distutils/_msvccompiler.py

Find def _find_vcvarsall(plat_spec): Add as the next line, add

    PathToVC=r"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
    return PathToVC, r""

And then make sure your visual studio bin directory is in your path.

If this doesn't work, there are other files you may need to edit including:

  • $PythonPath/Lib/distutils/msvc9compiler.py
  • $PythonPath/Lib/site-packages/setuptools/msvc9_support.py

THIS IS AN UP TO DATE ANSWER FOR WINDOWS USERS - VERY SIMPLE SOLUTION.

As pointed out by other, the problem is that python/cython etc. tries to find the same compiler they were built from, but this compiler does not exist on the computer. Most of the time, this compiler is a version of visual studio (2008, 2010 or 2013), but either such a compiler is not installed, or a newer version is installed and the system prevents from installing an older one. So, the solution is simple:

1) look at C:\Program Files (x86) and see if there is an installed version of Microsoft visual studio, and if it is newer than the version from which Python has been built. If not, install(/update to) the version from which Python has been built (see previous answers), or even a newest version and follow the next step.

2)If a newest version of Microsoft visual studio is already installed, we have to make Python/cython etc. believe that it is the version from which it has been built. And this is very simple: go to the the system environment variables and create the following variables, if they do not exist:

VS100COMNTOOLS

VS110COMNTOOLS

VS120COMNTOOLS

VS140COMNTOOLS

And set the field of these variables to

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools" (if visual studio 2008 is installed), or "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools" (if visual studio 2010 is installed) or "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools" (if visual studio 2013 is installed) or "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools" (if visual studio 2015 is installed).

This solution works for 32 bit versions of python. It may also work for 64 bit version but I've not tested; most probably, for 64 bit versions, the following additional steps must be performed:

3)add the path "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC" to the %PATH% environment variable (change the number of the version of visual studio according to you version).

4) from the command line, run "vcvarsall.bat x86_amd64"

That's all.


If you had installed Visual studio 2015 by the quick install, vcvarsall.bat is not there. But you can go to programm and fonctionalities, and modify the installation in order to install c++ tools, then vcvarsall.bat will be present.


Here's a simple solution. I'm using Python 2.7 and Windows 7.

What you're trying to install requires a C/C++ compiler but Python isn't finding it. A lot of Python packages are actually written in C/C++ and need to be compiled. vcvarsall.bat is needed to compile C++ and pip is assuming your machine can do that.

  1. Try upgrading setuptools first, because v6.0 and above will automatically detect a compiler. You might already have a compiler but Python can't find it. Open up a command line and type:

    pip install --upgrade setuptools

  2. Now try and install your package again:

    pip install [yourpackagename]

  3. If that didn't work, then it's certain you don't have a compiler, so you'll need to install one:
    http://www.microsoft.com/en-us/download/details.aspx?id=44266

  4. Now try again:

    pip install [yourpackagename]

And there you go. It should work for you.


In case anyone comes here looking for an answer for Python 3.5; you need Visual Studio 2015.

Get Visual Studio 2015 Community here: https://www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs.aspx, this worked for me with no further steps needed.

Many thanks to Ionel, apparently the only place on the web to find this information! http://blog.ionelmc.ro/2014/12/21/compiling-python-extensions-on-windows/


this worked for me (python 2.6):

installed free ms visual studio 2008 from http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express

copied vcvarsall.bat from "C:\Program Files\Microsoft Visual Studio 9.0\VC>" to "C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\"

the installer had already set this environment variable:

VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\

The solution to this problem is to set the following environment variable:

VS90COMNTOOLS

For instance:

set VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools

This error can be caused by not rebooting after installing Visual Studios, or not starting a new command prompt after installing.

Also the version of Visual Studios you can use to compile the extensions may depend on the version of python you are building for.


I tried the solution here to set an environment variable via the command line, but this didn't work. I did this both from a regular command prompt and from the Visual Studio Developer command prompt.

I could overcome this problem like this:

  1. go to the Environment variables screen and created a new variable there VS100COMNTOOLS and let it point to my Visual Studio installation folder C:\Program Files\Microsoft Visual Studio 12.0\Common7\Tools\
  2. Go to the above folder. Inside this folder there is the file vsvars32.bat. Copy this file and rename it to vsvarsall.bat

My configuration is Visual Studio 2013 (12.0) and Python 3.4.2


Install Visual Studio Express 2008 (9.0) from here: http://go.microsoft.com/?linkid=7729279

That's what fixed it for me.


It seems that Python is looking explicitly for Visual Studio 2008. I encountered this problem where it couldn't find vcvarsall.bat even though it was on the path.

It turns out that Visual Studio 2010 creates the following environment variable:

SET VS100COMNTOOLS=C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\

The fix is to create a variable called VS90COMNTOOLS and have that point to your Visual Studio 2010 common tools folder, e.g.

SET VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\

That fixed it for me and I can now build packages using the Visual Studio 2010 compiler.

You can also set the VS90 environment variable to point to the VS100 environment variable using the command below:

SET VS90COMNTOOLS=%VS100COMNTOOLS%

This cryptic error means that you don't have a C compiler installed. There was a discussion to propose a more explanative error (which is continued here, register and comment if you care about it!) but currently it is still not implemented.

To fix this issue you can either install the Visual Studio 2008 SDK which will take about a GB, or you can install the very small VCForPython27.msi but which is not well supported by distutils currently, here's the procedure:

1) install Microsoft Visual C++ Compiler for Python 2.7 from
http://www.microsoft.com/en-us/download/details.aspx?id=44266
2) Enter MSVC for Python command prompt
3) SET DISTUTILS_USE_SDK=1
4) SET MSSdk=1
5) you can then build your C extensions: python.exe setup.py ...

Steps 2 to 4 must be reproduced everytime before building your C extensions. This is because of an issue with the VCForPython27.msi which install the header files and vcvarsall.bat in folders of a different layout than the VS2008 SDK and thus confuse the compiler detection of distutils. This will get fixed in setuptools in Python 2.7.10.

Bug report and workaround by Gregory Szorc: http://bugs.python.org/issue23246

More info and a workaround for using %%cython magic inside IPython: https://github.com/cython/cython/wiki/CythonExtensionsOnWindows

/EDIT: Also, if you have another version of Python, you cannot use Microsoft Visual C++ for Python 2.7, which is a kind of mini-compiler specifically made by Microsoft for Python 2.7. In this case, you need to install the Visual Studio SDK that match your Python version, or a Windows SDK with the correct NET framework version. See here for more infos: https://github.com/cython/cython/wiki/CythonExtensionsOnWindows#using-windows-sdk-cc-compiler-works-for-all-python-versions


Looks like MS has released the exact package needed here. BurnBit here. Install it and then set the registry keys in this answer to point to C:\Users\username\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0


After installation of Visual Studio Community 2015 Edition on Windows 10 64 bit. This error did not go. Then I install Microsoft Visual C++ Compiler for Python 2.7. Since it requires vcvarsall.bat file. This file is no where in Visual studio Community 2015, but it was in Microsoft Visual C++ Compiler for Python 2.7. I also added its path into my environment variables but it also did not work. Then I un-install python 3.4.2 and deleted all the folders of python, and installed python 2.7. Finally I run pip using powershell and I was able to install my required package i.e. flask-user, by using.

pip install flask-user

Installing Visual C++ is a good first step, though I couldn't say for sure whether the 2010 version will work. Anyway give it a try.

Look for vcvarsall.bat in the Visual C++ installation directory (for Visual Studio 2010 it's in ProgramFiles\Microsoft Visual Studio 10.0\VC). Then add that directory to the system path. If you're doing this on the command line, you can try:

path %path%;c:\path\to\vs2010\bin

then try again to run whatever you were trying to run.

For more permanent effect, add it in the computer system path settings.


There is a confusing edge case for this on windows. If you follow the advice to install the 2007 windows, and you still get this error when doing python setup.py install directly, then it may be that the setup.py uses the old version of set up tools.

In particular, the code that points windows towards the right location for the windows installed compiler is in the __init__ method of the setuptools library, which means that you must in your setup.py use the setuptools module. Some older setup.py call methods directly from distutils.core. If this is the case then the setup.py will never find the windows installed compiler. This can be fixed by simply writing import setuptools as the first line of the setup.py file.

Reference: https://bugs.python.org/issue23246: Look about half way down for the quote from steve dower:

Setuptools has the code to find the compiler package. We deliberately put it there instead of in distutils to make sure more people would get it. I should probably port the extra check into 2.7.10, but the immediate fix is to import setuptools.


Note that there is a very simple solution.

  1. Download the software from http://www.microsoft.com/en-us/download/details.aspx?id=44266 and install it.

  2. Find the installing directory, it is something like "C:\Users\USER_NAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python"

  3. Change the directory name "C:\Users\USER_NAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0" to "C:\Users\USER_NAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\VC"

  4. Add a new environment variable "VS90COMNTOOLS" and its value is "C:\Users\USER_NAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\VC\VC"

Now everything is OK.


In 2015, if you still getting this confusing error, blame python default setuptools that PIP uses.

  1. Download and install minimal Microsoft Visual C++ Compiler for Python 2.7 required to compile python 2.7 modules from http://www.microsoft.com/en-in/download/details.aspx?id=44266
  2. Update your setuptools - pip install -U setuptools
  3. Install whatever python package you want that require C compilation. pip install blahblah

It will work fine.

UPDATE: It won't work fine for all libraries. I still get some error with few modules, that require lib-headers. They only thing that work flawlessly is Linux platform