pip install gives error: Unable to find vcvarsall.bat
Asked Answered
G

10

50

Using pip install zipline on Windows 8 with Python 2.7 gives me the error:

Downloading/unpacking six (from python-dateutil==2.1->delorean->zipline[all])
  Running setup.py egg_info for package six

Installing collected packages: blist, pytz, requests, python-dateutil, six
  Running setup.py install for blist
    building '_blist' extension
    error: Unable to find vcvarsall.bat
    Complete output from command C:\Python27\python.exe -c "import setuptools;__
file__='c:\\users\\ThatsMe\\appdata\\local\\temp\\pip-build-ThatsMe\\blist\\setup.py';ex
ec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" inst
all --record c:\users\ThatsMe\appdata\local\temp\pip-xvoky2-record\install-record.tx
t --single-version-externally-managed:

running install

running build

running build_py

running build_ext

building '_blist' extension

error: Unable to find vcvarsall.bat

Question: How can the error be resolved? Running pip install zipline[all] gives the same error...

Gladiolus answered 7/11, 2013 at 8:19 Comment(4)
You can find answer on this thread : #2818369Spoonbill
@Spoonbill That's Python 2.6Importunate
Either install gcc or Microsoft Visual Express Studio and follow the solutions on the link mentioned by Baart, they work fine for win8 and py2.7. I used codeblocks to install gcc.Superabundant
Answer is in this link https://mcmap.net/q/13521/-unable-to-find-vcvarsall-bat-using-python-3-3-in-windows-8 enjoy!Shears
H
23

You could use ol' good easy_install zipline instead.

easy_install isn't pip but one good aspect of it is the ability to download and install binary packages too, which would free you for the need having VC++ ready. This of course relies of the assumption that the binaries were prepared for your Python version.

UPDATE:

Yes, Pip can install binaries now!

There's a new binary Python archive format (wheel) that is supposed to replace "eggs". Wheels are already supported by pip. This means you'll be able to install zipline with pip without compiling it as soon as someone builds the wheel for your platform and uploads it to PyPI.

Hardback answered 7/11, 2013 at 8:46 Comment(4)
Why the downvote? Does pip also install binaries now?Hardback
This is a workaround. Though useful, it doesn't answer the question - which is how to resolve the error.Supraliminal
Well, that's true, and I wouldn't mind if the accepted answer went to a non-workaround. Still I'll always emphasise this, since one shouldn't need to install the whole Microsoft Visual Studio just to install a Python package on Windows.Hardback
If no binary package exists, you will get error: Setup script exited with error: Unable to find vcvarsall.bat even with easy_install.Epilogue
N
58

The problem here is the line 292 (Using Python 3.4.3 here) in $python_install_prefix/Lib/distutils/msvc9compiler.py which says:

VERSION = get_build_version()

This only checks for the MSVC version that your python was built with. Just replacing this line with your actual Visual Studio version, eg. 12.0 for MSVC2013

VERSION = 12.0

will fix the issue.

UPDATE: Turns out that there is a good reason why this version is hardcoded. MSVC C runtime is not required to be compatible between major versions. Hence when you use a different VS version you might run into runtime problems. So I advise to use VS 2008 (for Python 2.6 up to 3.2) and VS2010 for (Python 3.3 and later) until this issue is sorted out.

Binary compatibility will arrive with VS 2015 (see here) along with Python 3.5 .

For Python 2.7 users Microsoft released a special Microsoft Visual C++ Compiler for Python 2.7 which can be used without installing the whole VS 2008.

Nationalism answered 30/4, 2014 at 20:20 Comment(7)
The other solutions are just plain wrong. You don't need VS in your PATH at all! This should be the accepted solution. Worked 100% for me with VS2013. Please upvote.Auspex
This breaks with an error of '"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\cl.exe"' failed with exit status 2Lisle
Yeah, it didn't finish - coz there was a linking error or somehtingLisle
I wonder that on my PC a path to VS 12 is [code]"C:\Program Files (x86)\Microsoft Visual Studio 11.0". So I could fix the problem with VERSION = 11.0Ludwog
@MeLight, ismail, I just tried the solution & I landed up to the error faced by MeLight. how to get rid of the error : "error: command '"C:\Program Files\Microsoft Visual Studio 12.0\VC\BIN\cl.exe"' f ailed with exit status 2". Because it ultimately takes you back to the square oneExhaustive
@Fooo thats a compilation error, probably the package does not support MSVC?Nationalism
A solution to "failed with exit status 2" is here that worked for me is here:#20461390Heady
H
23

You could use ol' good easy_install zipline instead.

easy_install isn't pip but one good aspect of it is the ability to download and install binary packages too, which would free you for the need having VC++ ready. This of course relies of the assumption that the binaries were prepared for your Python version.

UPDATE:

Yes, Pip can install binaries now!

There's a new binary Python archive format (wheel) that is supposed to replace "eggs". Wheels are already supported by pip. This means you'll be able to install zipline with pip without compiling it as soon as someone builds the wheel for your platform and uploads it to PyPI.

Hardback answered 7/11, 2013 at 8:46 Comment(4)
Why the downvote? Does pip also install binaries now?Hardback
This is a workaround. Though useful, it doesn't answer the question - which is how to resolve the error.Supraliminal
Well, that's true, and I wouldn't mind if the accepted answer went to a non-workaround. Still I'll always emphasise this, since one shouldn't need to install the whole Microsoft Visual Studio just to install a Python package on Windows.Hardback
If no binary package exists, you will get error: Setup script exited with error: Unable to find vcvarsall.bat even with easy_install.Epilogue
C
9

If you are getting this error on Python 2.7 you can now get the Microsoft Visual C++ Compiler for Python 2.7 as a stand alone download.

If you are on 3.3 or later you need to install Visual Studio 2010 express which is available for free here: https://www.visualstudio.com/downloads/download-visual-studio-vs#d-2010-express

If you are 3.3 or later and using a 64 bit version of python you need to install the Microsoft SDK 7.1 that ships a 64 bit compiler and follow the directions here Python PIP has issues with path for MS Visual Studio 2010 Express for 64-bit install on Windows 7

Chaps answered 7/3, 2015 at 3:39 Comment(1)
I didn't have the compiler installed so downloading and installing from this link immediately fixed my issue with Python 2.7.Anesthetic
T
7

First, you should look for the file vcvarsall.bat in your system.

If it does not exist, I recommend you to install Microsoft Visual C++ Compiler for Python 2.7. This will create the vcvarsall.bat in "C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0" if you install it for all users.

The problem now is in the function find_vcvarsall(version) in the C:/Python27/Lib/distutils/msvc9compiler.py module, which is looking for the vcvarsall.bat file.

Following the function calls you will see it is looking for an entry in the registry containing the path to the vcvarsall.bat file. It will never find it because this function is looking in other directories different from where the above-mentioned installation placed it, and in my case, the registry didn't exist.

The easiest way to solve this problem is to manually return the path of the vcvarsall.bat file. To do so, modify the function find_vcvarsall(version) in the msvc9compiler.py file with the absolute path to the vcvarsall.bat file like this:

def find_vcvarsall(version):
    return r"C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat"

This solution worked for me.

If you already have the vcvarsall.bat file you should check if you have the key productdir in the registry:

(HKEY_USERS, HKEY_CURRENT_USERS, HKEY_LOCAL_MACHINE or HKEY_CLASSES_ROOT)\Software\Wow6432Node\Microsoft\VisualStudio\version\Setup\VC

Where version = msvc9compiler.get_build_version()

If you don't have the key just do:

def find_vcvarsall(version):
        return <path>\vcvarsall.bat

To understand the exact behavior check msvc9compiler.py module starting in the find_vcvarsall(version) function.

Toponymy answered 5/2, 2015 at 23:8 Comment(0)
F
3

Simply because you don't have c++ compiler installed there in your machine, check the following

  • Download Microsoft Visual C++ 2008 from this page. That is a generally useful page anyway, so you should probably bookmark it. For Python 3.3+ use MS Visual C++ 2010. Install it.

  • Open Windows explorer (the file browser) and search for the location of ‘vcvarsall.bat’ and cut it to your clipboard.

  • run regedit from the Windows start key. You will need admin privilges.

  • Add a registry entry to HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir (64 bit Windows) or HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir (32 bit) as described here.

Hint: 0.9 in the registery directory is the currently installed version of your visual studio, if you running VS 2013, you have to find the path HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\12.0....

  • At the Windows start key, type cmd to get a command shell. If you need to, go to your virtual environment and run activate.bat.

  • pip install or whatever you use to install it.

Forwent answered 24/2, 2014 at 18:13 Comment(5)
When I install MVC2008 there's no file vcvarsall anywhere, and there's no VisualStudio\9.0 in the registryVallonia
@StéphaneLaurent The redistributable will not work. You need VS 2008 Express with the C++ compiler - refer to this answer for better instructions.Hydromedusa
Thank you @Pakman. But I have spent one day to attempt to install this library, and finally I have strongly decided to never continue these frustrating unsucessful attempts. This is a real nightmare.Vallonia
@Stéphane well here we are 2 years later and the problem is actually worse. Most of the "fixes" on SO no longer apply and the best method (updating pip to 6.x) breaks your environmental variables.Rearm
So to elaborate, I downloaded VC 2008 (since I'm using Python 2.7), added the registry key HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir with a value of C:\Users\<username>\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0, and ran "c:\python27\python setup.py build --build-base=./build install" from a Visual C++ 2008 64-bit Command Prompt. This worked. Thanks a lot!Commons
K
2

You need to have Visual Studio's bin dir in your path. Pip install is trying to compile some C code.

Katelyn answered 7/11, 2013 at 8:30 Comment(2)
Looks for vcvarsall.bat in your drive. Add that location to your path.Katelyn
In my case solution was manual install through pip of the package, since it supports wheel: trollius.readthedocs.org/#install-trollius-on-windows-using-pipFeer
U
1

I spent hours researching this vcvarsall.bat as well. Most answers on SO focus on Python 2.7 and / or creating workarounds by modifying system paths. None worked for me. This solution worked out of the box for Python 3.5 and (I think) is the "correct" way of doing it.

  1. See this link -- it describes the Windows Compilers to use for different versions of Python: https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.0_standalone:_Visual_C.2B-.2B-_Build_Tools_2015_.28x86.2C_x64.2C_ARM.29

  2. For Python 3.5, download this: https://www.microsoft.com/en-us/download/details.aspx?id=49983

  3. For me, I had to run C:\Program Files (x86)\Microsoft Visual C++ Build Tools\Visual C++ x64 Native Build Tools Command Prompt for it to work. From that command prompt, I ran "pip install django_compressor" which was the particular package that was causing me an issue, and it worked perfectly.

Hope this saves someone some time!

Uke answered 23/3, 2016 at 20:48 Comment(1)
Direct link for the Visual C++ Build Tools: landinghub.visualstudio.com/visual-cpp-build-toolsEspalier
D
0

Thanks to "msoliman" for his hint, however his answer doesn't give clear solution for those who doesn't have VS2010
For example I have VS2012 and VS2013 and there are no such KEYs in system registry.

Solution:
Edit file: "[Python_install_loc]/Lib/distutils/msvc9compiler.py"
Change on line 224:

productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
                               "productdir")

to:

productdir = "C:\Program Files (x86)\Microsoft Visual Studio [your_vs_version(11/12...)]\VC"

and that should work

Dipsomaniac answered 29/4, 2014 at 10:47 Comment(1)
You need to use the same version of the compiler and tools that python itself was installed. Otherwise you'll get weird issues.Timi
S
0

If you are trying to install matplotlib in order to work with graphs on python. Try this link. https://github.com/jbmohler/matplotlib-winbuild. This is a set of scripts to build matplotlib from source on the MS Windows platform.

To build & install matplotlib in your Python, do:

git clone https://github.com/matplotlib/matplotlib
git clone https://github.com/jbmohler/matplotlib-winbuild
$ python matplotlib-winbuild\buildall.py

The build script will auto-detect Python version & 32/64 bit automatically.

Somnambulism answered 30/12, 2014 at 12:7 Comment(1)
why am I not able to run the lst command python matplotlib-winbuild\buildall.py . I get this error python: can't open file 'buildall.py': [Errno 2] No such file or directory even though this file exists hereHeadsail
M
0

I appreciate this might not be the answer to resolving on 3.4 but I tried a huge variety of things to fix this on 3.4 and thought this might be useful if someone is time pressed or doesn't have the know-how to correct it (in my case, work demands).

With exactly the same setup, I found that my installation problems only happened with Python 3.4. When I changed to 2.7, all my issues seemed to be resolved.

We have a rather overzealous security setup though so I'm going to try the same on my home version (still 3.4) and see if I have any more joy. My inclination is that my VS version has somehow been restricted and the answers above should help. If I find anything more tonight I'll add further detail.

This is my first reply, not the most technical I'm afraid!

Mazza answered 10/4, 2015 at 17:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.