Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imitate Visual C++ with MinGW or other C++ compilers (for Python packages based on Visual C++) #100764

Closed
lorenzznerol opened this issue Jun 22, 2020 · 3 comments

Comments

@lorenzznerol
Copy link

lorenzznerol commented Jun 22, 2020

######################################################################
This is a full copy of https://stackoverflow.com/questions/62149329/imitate-visual-c-with-mingw-or-other-c-compilers-for-python-packages-based

With an interesting comment from @david Macek
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).
######################################################################

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 https://stackoverflow.com/questions/29846087/microsoft-visual-c-14-0-is-required-unable-to-find-vcvarsall-bat/51087608#51087608

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?

@IllusionMH
Copy link
Contributor

This is issue tracker for Visual Studio Code editor, not Microsoft Visual Studio (year).

Are you sure that this issue related to Visual Studio Code?

@lorenzznerol
Copy link
Author

lorenzznerol commented Jun 22, 2020

yes, I refer to Visual Studio Code here. I also wondered about it, but you have to install Microsoft Visual C++ in order to have C++ available for a lot of packages in Python which do not accept any other C++ compiler, and now the question is if Visual Studio Code could give a smart and lightweight alternative to this quite clumpsy approach. (Not the right comparison, but the GB disk size goes into the same direction: For Python to work in Visual Studio Code, you can also just install Python instead of installing 4 GB Anaconda ;) I just trust vscode to be smarter and change things here faster than the Microsoft Visual Studio approach which I do not even need to change, as there, the 4 GB are probably needed.

@dbaeumer
Copy link
Member

@lorenzznerol the VS Code core editor is not the right place for this. It is either the CPP extension or better the Python extension. Please open issues against these extensions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants