3

Is there a way to use MinGW as a substitute of MS Visual C++? A lot of Python packages need VS C++ to be installed: 4.5 GB of disk space! MinGW takes only 450 MB and reaches the same aim to compile C/C++.

I am using Visual Studio Code, and I try to avoid the Microsoft Visual C++ installation that is proposed here under 3) --> You can also install just the C++ Build Tools: https://code.visualstudio.com/docs/cpp/config-msvc/#_prerequisites

Perhaps there is just a trick needed to imitate MS Visual C++ with MinGW, so that the Python packages directly find the MinGW compiler as if it were MS Visual C++? Perhaps adding symlinks to the lib directory and adding some system variable path?

My question is strongly linked with Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)

The error that I get when I install a package that needs MS Visual C++ as an example, installing pip install dtaidistance:

  creating build\temp.win-amd64-3.7\Release\dtaidistance
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\Admin\Anaconda3\lib\site-packages\numpy\core\include -IC:\Users\Admin\Anaconda3\include -IC:\Users\Admin\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include" /Tcdtaidistance/dtw_c.c /Fobuild\temp.win-amd64-3.7\Release\dtaidistance/dtw_c.obj /openmp /Ox /fp:fast /favor:INTEL64 /Og
  cl : Befehlszeile warning D9035 : Die Option "Og" ist veraltet und wird in einer der n„chsten Versionen entfernt.
  dtw_c.c
  C:\Users\Admin\Anaconda3\include\pyconfig.h(59): fatal error C1083: Datei (Include) kann nicht ge”ffnet werden: "io.h": No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.26.28801\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
  ----------------------------------------
  ERROR: Failed building wheel for dtaidistance
  Running setup.py clean for dtaidistance
Failed to build dtaidistance
Installing collected packages: dtaidistance
  Running setup.py install for dtaidistance ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\Admin\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-install-5lb8uekg\\dtaidistance\\setup.py'"'"'; __file__='"'"'C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-install-5lb8uekg\\dtaidistance\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Admin\AppData\Local\Temp\pip-record-dzfe2cwr\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\Admin\AppData\Local\Temp\pip-install-5lb8uekg\dtaidistance\

After installing only MSVC (1.8 GB) - only that, as a test to see if that is already all I need: installation of only MSVC

We see that the installation still fails, but the error changes slightly, as at least ERROR: Failed building wheel for dtaidistance has disappeared now, see the following screenshot:

    creating build\temp.win-amd64-3.7\Release\dtaidistance
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\Admin\Anaconda3\lib\site-packages\numpy\core\include -IC:\Users\Admin\Anaconda3\include -IC:\Users\Admin\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include" /Tcdtaidistance/dtw_c.c /Fobuild\temp.win-amd64-3.7\Release\dtaidistance/dtw_c.obj /openmp /Ox /fp:fast /favor:INTEL64 /Og
    cl : Befehlszeile warning D9035 : Die Option "Og" ist veraltet und wird in einer der n„chsten Versionen entfernt.
    dtw_c.c
    C:\Users\Admin\Anaconda3\include\pyconfig.h(59): fatal error C1083: Datei (Include) kann nicht ge”ffnet werden: "io.h": No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.26.28801\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\Admin\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-install-jr44cxi8\\dtaidistance\\setup.py'"'"'; __file__='"'"'C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-install-jr44cxi8\\dtaidistance\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Admin\AppData\Local\Temp\pip-record-t_8xl3_a\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

After installing the other 4 checkboxes directly below the MSVC checkbox in the screenshot of MS Visual++ above, I could install the package.

Perhaps changing the assigned C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.26.28801\\bin\\HostX86\\x64\\cl.exe somewhere in the python settings to MinGW gcc compiler C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\c++.exe might already solve it?

questionto42
  • 7,175
  • 4
  • 57
  • 90
  • 1
    The C++ ABIs (possibly headers even) of GCC and MSVC are just incompatible. You might have some luck using Clang, but I don't guarantee anything. /// If you're concerned about disk space, you might try installing the requisites and then stripping the parts irrelevant to Python packages. There might even be a way to make something of a portable MSVC toolchain, but don't distribute it (I believe it's not allowed in the license). – David Macek Jun 03 '20 at 20:03
  • I have given feedback on the Visual Studio Code Survey what I would like to improve: offering a light Visual C++ for Python packages to run, or offering settings that can use Clang, MinGW or other compilers instead of Visual C++. It is unlikely that someone will care about it as it is a Visual C++ problem and not a Visual Studio Code problem. And everyone has enough disk space nowadays. I still try to save disk space, I am mostly working on a netbook with 64GB. Apart from disk space, installing both MinGW and Visual C++ is not nice. At least I have tried it with that little feedback now. – questionto42 Jun 04 '20 at 13:07
  • I have opened this issue with a copy of this SO question on https://github.com/microsoft/vscode-cpptools/issues/5695 – questionto42 Jun 25 '20 at 11:15

1 Answers1

1

There is no chance for this idea.

  1. MSVC

I have sent feedback to them, yet I did not get any reply. A Python developer assured that they know about this size issue anyway and do not like it either. The only chance is a change from MSVC developers themselves. It is unlikely, but not impossible, that the size will be reduced in future releases by the MSVC team.

  1. Python distutils workaround

The Python community will not provide a distutils workaround, see https://discuss.python.org/t/imitate-visual-c-with-mingw-or-other-c-compilers-for-python-packages-based-on-visual-c/4609/11.

Quote from the Python forum:

There was a workaround until Python 3.4 which might also be an approach now: Use MinGW compiler till Python 3.4 by adding a “distutils.cfg” to the folder “\Lib\distutils” in Python install directory. It would be nice to have that MinGW “distutils.cfg” workaround for the recent Python versions as well.

Now it turns out that distutils will not be a realistic workaround.

  • There is no one who will work on it. A Python developer who was involved in the project before: Maybe there is ...

... someone else who might offer to help. But I wouldn’t be too optimistic.

  • And a deprecation issue:

As an aside, now that setuptools has fully taken on distutils, we’ll be deprecating it in the standard library (soon). So this request in future would have to be made to each project implementing a build tool.

questionto42
  • 7,175
  • 4
  • 57
  • 90