用 MinGW 或其他 C++ 编译器模仿 Visual C++(适用于基于 Visual C++ 的 Python 包) [英] Imitate Visual C++ with MinGW or other C++ compilers (for Python packages based on Visual C++)

查看:107
本文介绍了用 MinGW 或其他 C++ 编译器模仿 Visual C++(适用于基于 Visual C++ 的 Python 包)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 MinGW 来替代 MS Visual C++?很多 Python 包需要安装 VS C++:4.5 GB 磁盘空间!MinGW 只需要 450 MB 并达到编译 C/C++ 的相同目标.

我使用的是 Visual Studio Code,并且我尽量避免在此处建议的 Microsoft Visual C++ 安装 3) --> 您也可以只安装 C++ 构建工具:

我们看到安装仍然失败,但错误略有变化,至少ERROR: Failed building wheel for dtaidistance现在已经消失了,看下面的截图:

 创建 build\temp.win-amd64-3.7\Release\dtaidistanceC:\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/Ogcl : Befehlszeile 警告 D9035 : Die Option "Og" ist veraltet und wird in einer der n„chsten Versionen entfernt.dtw_c.cC:\Users\Admin\Anaconda3\include\pyconfig.h(59): 致命错误 C1083: Datei (Include) kann nicht ge"ffnet werden: "io.h": No such file or directory错误:命令'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.26.28801\\bin\\HostX86\\x64\\cl.exe' 失败,退出状态为 2---------------------------错误:命令出错,退出状态为 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 检查日志以获取完整的命令输出.

在上面 MS Visual++ 的屏幕截图中直接在 MSVC 复选框下方安装其他 4 个复选框后,我可以安装包.

也许改变分配的 C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.26.28801\\bin\\HostX86\\x64\\cl.exe 在 python 设置到 MinGW gcc 编译器的某处 C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\c++.exe 可能已经解决了?

解决方案

没有答案.

  1. MSVC

我已经向他们发送了反馈,但我没有得到任何回复.一位 Python 开发人员保证,他们无论如何都知道这个大小问题,并且也不喜欢它.唯一的机会是 MSVC 开发人员自己的改变.MSVC 团队在未来的版本中不太可能(但并非不可能)减小大小.

  1. Python distutils 解决方法

Python 社区不会提供 distutils 解决方法,请参阅 https://discuss.python.org/t/imitate-visual-c-with-mingw-or-other-c-compilers-for-python-packages-based-on-visual-c/4609/11.

引用自 Python 论坛:

<块引用>

在 Python 3.4 之前有一个解决方法,它也可能是一个现在的方法:通过添加一个使用 MinGW 编译器直到 Python 3.4distutils.cfg"到Python安装中的\Lib\distutils"文件夹目录.拥有 MinGW distutils.cfg" 会很好也适用于最近的 Python 版本.

现在事实证明,distutils 并不是一个现实的解决方法.

  • 没有人愿意为此工作.一位之前参与过该项目的 Python 开发者:也许有...
<块引用>

... 可能会提供帮助的其他人.但我不会太乐观.

  • 还有一个弃用问题:
<块引用>

顺便说一句,既然 setuptools 已经完全采用了 distutils,我们将在标准库中弃用它(很快).所以这个请求在必须为每个实施构建的项目制定未来工具.

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:

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?

解决方案

There is no answer.

  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.

这篇关于用 MinGW 或其他 C++ 编译器模仿 Visual C++(适用于基于 Visual C++ 的 Python 包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆