14

When I try to build one package:

C:\Linter\intlib\PYTHON>python setup.py build

I get this error message:

running build

running build_ext

building 'LinPy' extension

error: Unable to find vcvarsall.bat

This is my Python version:

Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)] on win32

And I'm working on Windows 10 x64. I know about this thread and dozens of others (like this and this and the list goes on). So, I guess I tried almost everything, but nothing works. It seems like all those threads have become outdated, so I need some new receipt. BTW. I tried this:

SET VS90COMNTOOLS=%VS100COMNTOOLS%

And this (in Visual Studio 2015 Visual Studio Command Prompt):

set DISTUTILS_USE_SDK=1

I looked for vcvarsall.bat everywhere on my machine, but could not find it.

I investigated this folder C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools, but it does not contain any .bat files. Anyway, after all my manipulations python setup.py build still raises the very same error. So, I need help. Thanks!

Community
  • 1
  • 1
Jacobian
  • 10,122
  • 29
  • 128
  • 221
  • the env variable for visual studio 2015 is called `%VS140COMNTOOLS%` – smerlin May 30 '16 at 22:01
  • The easiest and [officially supported](https://hg.python.org/cpython/file/v3.4.4/PCbuild/readme.txt) build environment is VS 2010 Professional. – Eryk Sun May 31 '16 at 00:34
  • I used to build with the VS 2010 Express and the Windows SDK v7.1 (all updates applied -- in the right sequence), but it was a pain to build an x64 version because I had to manually edit the project files to separate the win32 and amd64 subprojects. With the SDK compiler I had to use `SetEnv.cmd` to set up for `/x86` or `/x64`, but couldn't do both. – Eryk Sun May 31 '16 at 00:35
  • @smerlin. If you look at my Python version (... MSC v.1600 ...), you will see that it was built with VS 2010. But I do not know if it matters. – Jacobian May 31 '16 at 04:41
  • @Jacobian, it matters in that an extension built with a different version of Visual Studio links to a different C runtime DLL that has its own heap (for allocating memory), standard I/O `FILE` streams, and low I/O file descriptors. Thus it's potentially a problem. In your question you mention "Visual Studio 2015 Visual Studio Command Prompt" (used for Python 3.5), so it's not clear that you have Visual Studio 2010 installed, or which version of VS2010 is installed. – Eryk Sun May 31 '16 at 05:13
  • @eryksun. Sorry, if it was misleading. But let me point it again, that I have not installed Visual Studio 2010. And when I say, that I'm using Visual Studio 2015, I mean that it is installed on my machine. However, it seems like Python was somehow built with VS 2010. – Jacobian May 31 '16 at 09:12

7 Answers7

22

The issue is caused because you don't have a compiler installed for the receptive build you are trying to run.


The following is what you may require as per the MS Python Engineering community,

Python Version  |You will need
------------------------------------
3.5 and later   |Visual C++ Build Tools 2015 or Visual Studio 2015
3.3 and 3.4     |Windows SDK for Windows 7 and .NET 4.0
                |(Alternatively, Visual Studio 2010 if you have access to it)
2.6 to 3.2      |Microsoft Visual C++ Compiler for Python 2.7

You will need to install: Windows SDK for Windows 7 and .NET 4.0 or VS 2010


Source: How to deal with the pain of “unable to find vcvarsall.bat”

Ani Menon
  • 27,209
  • 16
  • 105
  • 126
  • Unfortunatelly, it does not help. I tried everything and it still does not work. When I try to install Windows SDK for Windows 7, it says that I need .NET 4.0, byt when I try to install .NET 4.0, then it says that I already have .NET installed on my machine. When I install VS 2010, I get some iso file. which contains numerous files. I do not know what to do with all this. The last liunk is also useless. As I've already said in my question I tried this commmnd `set DISTUTILS_USE_SDK=1` in VS command prompt, but it has no effect. – Jacobian Jun 06 '16 at 17:37
  • 2
    So, unfortunatelly, I can't accept your asnwer. And the problem of "unable to find vcvarsall.bat" is still pain in the as*. – Jacobian Jun 06 '16 at 17:40
  • 1
    This should help: [link](http://stackoverflow.com/questions/32091593/cannot-install-windows-sdk-7-1-on-windows-10). Also after that [WinSDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk) – Ani Menon Jun 06 '16 at 18:05
  • It does not help. When I try to change `HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v4\Client\Version` I get an error message - "unable to change Version ...". So, nothing works. – Jacobian Jun 06 '16 at 18:15
  • As I said, I need a detailed canonical answer. Unfortunatelly, old links do not work and do not provide any help. – Jacobian Jun 06 '16 at 18:23
  • @Jacobian good luck. MS says those are the steps, if they don't work something else must be wrong. And if its specific to your OS Version you should put it up on their support site. – Ani Menon Jun 06 '16 at 18:26
  • If only those steps worked (( But still, thank you, Ani, for trying to help! – Jacobian Jun 06 '16 at 19:46
  • 2
    @ani-menon, installing Visual C++ Build Tools 2015 (not 2017) on my Windows 10 machine to build Cython apps on Python 3.6 worked for me. I downloaded the package from http://landinghub.visualstudio.com/visual-cpp-build-tools. Thank you. – vlmercado Jun 10 '17 at 00:30
  • @vlmercado The link is broken. – Idonknow Jun 20 '20 at 02:17
  • @Idonknow [visual-cpp-build-tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) – Ani Menon Jun 21 '20 at 04:26
  • I can confirm this won't work on python 3.8. only works on 3.6 – greendino Sep 28 '20 at 01:18
4

I did a search for a python wheel of LinPy unfortunately there happened to be none.

Cython has a very good workaround for setting up a windows C/C++ compiler for builds in python. You can find it here. Since you've already downloaded the SDK/.NET framework, you should go ahead and install it as it will be needed as part of the steps. If your system reports there is already an existing version, you may uninstall, restart and reinstall.

A hackish alternative is to search for vcvars32.bat or vcvarsall.bat (these batch files are only to set up environment variables for compile time) in your Visual studio installation directory. If you don't find any, then you should install the SDK. I managed to do a work around by hardcoding the path to vcvars32.bat or vcvarsall.bat in the find_vcvarsall function of C:\Python34\Lib\distutils\msvc9compiler.py, but there is a missing library (ISL - Integer Set Library). I think it's because I am using VC11.

enter image description here

I don't have the SDK, but you may try these and see what happens from your end

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
  • LinPy - is a driver for free Linter SQL Server. It can be downloaded from this site - https://linter.ru/en/. When you install it, in one of Linter folders you will see PYTHON folder, containing setup.py file... As for your advice, I will check it today. Thanks! – Jacobian Jun 08 '16 at 06:57
  • hacking *find_vcvarsall* is the right way for me when using vs_buildtools_2017. **Distutils** should better really evolve **msvc9compiler.py** to a modern one. – caoanan Apr 23 '18 at 02:33
3

You can ease your pains with Microsoft compilers for Python 3.4 by installing mingwpy or libpython (not both):

pip install -i https://pypi.anaconda.org/carlkl/simple mingwpy

conda install libpython

denfromufa
  • 5,610
  • 13
  • 81
  • 138
  • Thanks! But can you provide some example on how to use `mingwpy` or `libpython` to build some library that requires `vcvarsall.bat`? Let it be some imaginary library `foobar`. – Jacobian Jun 07 '16 at 05:18
  • Libpython from anaconda uses mingw to automagically build your extensions without any pre-configuration. Note that if your build script setup.py is using distutils, then importing setuptools will monkey patch distutils for good reasons. – denfromufa Jun 07 '16 at 09:50
  • I did not use mingwpy, but supposedly in winpython distro it works out of box, like libpython in anaconda. – denfromufa Jun 07 '16 at 09:52
  • The library should not be depending directly on vcvarsall.bat - it is compiler setup script. – denfromufa Jun 07 '16 at 09:54
  • But still can you provide a command that will build a library. Prior to all this my command looked like `python setup.py build`. And now when using `mingwpy` or `libpython` how it will look like? Will it stay the same? – Jacobian Jun 07 '16 at 15:47
  • should be the same – denfromufa Jun 07 '16 at 17:01
  • 1
    Unfortunatelly, it does not work. I've just installed `mingwpy`. As a result I see this in the console: `Installing collected packages: mingwpy Successfully installed mingwpy-0.1.0b3`. However, when I run `python setup.py build` right after installation, then I still get the very same error message `error: Unable to find vcvarsall.bat` – Jacobian Jun 07 '16 at 17:44
  • 1
    So, it seems like this problem is totally unbreakable on Windows 10 and with Python 3.4 in hand. – Jacobian Jun 07 '16 at 17:46
1

Step 1: Install Visual C++ 2010 Express from here.

(Do not install Microsoft Visual Studio 2010 Service Pack 1 )

Step 2: Remove all the Microsoft Visual C++ 2010 Redistributable packages from Control Panel\Programs and Features. If you don't do those then the install is going to fail with an obscure "Fatal error during installation" error.

Step 3: Install offline version of Windows SDK for Visual Studio 2010 (v7.1) from here. This is required for 64bit extensions. Windows has builtin mounting for ISOs like Pismo.

Step 4: You need to install the ISO file with Pismo File Mount Audit Package. Download Pismo from here

Step 5: Right click the downloaded ISO file and choose mount with Pismo. Thereafter, install the Setup\SDKSetup.exe instead of setup.exe.

Step 6a: Create a vcvars64.bat file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 by changing directory to C:\Program Files (x86)\Microsoft Visual Studio version\VC\ on the command prompt. Type command on the command prompt: cd C:\Program Files (x86)\Microsoft Visual Studio version\VC\r

Step 6b: To configure this Command Prompt window for 64-bit command-line builds that target x86 platforms, at the command prompt, enter: vcvarsall x86</p>

1

Updated solution for Python 3.9.X with latest SDK and build tools:

Step 1: Install and run build tools for VS 2019 https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019

Step 2: Select Windows 10 SK (10.0.20348.0+) and MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.29-16.10+) from individual components section and and click Install

Step 3: Proceed to build your python application with vcvarsall.bat now being present.

Note: vcvarsall.bat can be found in C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build

rgbhex00
  • 97
  • 3
0

To use mingwpy instead of the MSVC compiler create a file named pydistutils.cfg in the folder %USERPROFILE% with the following content:

[config]
compiler=mingw32
[build]
compiler=mingw32
[build_ext]
compiler=mingw32

see also How to use MinGW's gcc compiler when installing Python package using Pip?

Community
  • 1
  • 1
carlkl
  • 26
  • 3
0

To add to what Ani Menon answered and addressing Jacobian's(OP) issues he had in response... I had the same issue so I followed this StackOverflow post regarding changing the version number of .NET in the registry temporarily. It's probably a good idea to change the registry value back after.

https://stackoverflow.com/a/33260090/4637870

This succeeded in getting me past the .NET 4 not installed error, but then I was presented with another error towards that the installation was unsuccessful.

I had to remove both the x86 and x64 instances of the Microsoft Visual C++ 2010 Redistributable and let the SDK install it for me. After doing so I was able to make it all the way through the setup without error. This is where I got my information from:

Forum: https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/381299c9-1bf4-44d4-989c-871735c6b4ca/windows-sdk-for-windows-7-and-net-framework-4-wont-install?forum=windowssdk

Fix: https://support.microsoft.com/de-de/help/2717426/windows-sdk-fails-to-install-with-return-code-5100

I tried running pip on the same package and the error: Unable to find vcvarsall.bat is gone. Now I have a ValueError: ['path'] but thats another issue. Hope this information helps.

For info on my setup im running windows 7 and python 3.4

Benargee
  • 162
  • 1
  • 2
  • 8