用 MinGW 或其他 C++ 编译器模仿 Visual C++(对于 Python 基于 Visual C++ 的包)?
Imitate Visual C++ with MinGW or other C++ compilers (for Python packages based on Visual C++)?
有没有办法使用 MinGW 代替 MS Visual C++?许多 Python 软件包需要安装 VS C++:4.5 GB 磁盘 space! MinGW 只占用 450 MB 并达到编译 C/C++ 的相同目标。
我正在使用 Visual Studio 代码,我尽量避免安装 3) 下建议的 Microsoft Visual C++ --> 您也可以只安装 C++ 构建工具: https://code.visualstudio.com/docs/cpp/config-msvc/#_prerequisites
也许只需要一个技巧就可以用 MinGW 模仿 MS Visual C++,这样 Python 包就可以像 MS Visual C++ 一样直接找到 MinGW 编译器?
也许将符号链接添加到 lib 目录并添加一些系统变量路径?
我的问题与 Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)
密切相关
安装需要MS Visual C++的包时报错,安装pip install dtaidistance
:
creating build\temp.win-amd64-3.7\Release\dtaidistance
C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.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 Studio19\BuildTools\VC\Tools\MSVC.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\
仅安装 MSVC (1.8 GB) 后 - 仅此而已,作为测试以查看是否已经满足我的全部需求:
我们看到安装还是失败了,但是报错有点变化,现在至少ERROR: Failed building wheel for dtaidistance
已经消失了,看下面的截图:
creating build\temp.win-amd64-3.7\Release\dtaidistance
C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.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 Studio19\BuildTools\VC\Tools\MSVC.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.
在上面的 MS Visual++ 屏幕截图中的 MSVC 复选框正下方安装其他 4 个复选框后,我可以安装包。
也许将 python 设置中指定的 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64\cl.exe
更改为 MinGW gcc 编译器 C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\c++.exe
可能已经解决了?
这个想法没有机会了。
- MSVC
我已经向他们发送反馈,但我没有得到任何回复。一位 Python 开发人员保证他们无论如何都知道这个尺寸问题并且也不喜欢它。唯一的机会是 MSVC 开发人员自己进行更改。 MSVC 团队在未来的版本中不太可能(但并非不可能)缩小大小。
- 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 论坛:
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.
现在事实证明,distutils 不是一个现实的解决方法。
- 没有人会处理它。之前参与该项目的一位Python开发人员:也许有...
... someone else who might offer to help. But I wouldn’t be too optimistic.
- 还有一个弃用问题:
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 代替 MS Visual C++?许多 Python 软件包需要安装 VS C++:4.5 GB 磁盘 space! MinGW 只占用 450 MB 并达到编译 C/C++ 的相同目标。
我正在使用 Visual Studio 代码,我尽量避免安装 3) 下建议的 Microsoft Visual C++ --> 您也可以只安装 C++ 构建工具: https://code.visualstudio.com/docs/cpp/config-msvc/#_prerequisites
也许只需要一个技巧就可以用 MinGW 模仿 MS Visual C++,这样 Python 包就可以像 MS Visual C++ 一样直接找到 MinGW 编译器? 也许将符号链接添加到 lib 目录并添加一些系统变量路径?
我的问题与 Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)
密切相关安装需要MS Visual C++的包时报错,安装pip install dtaidistance
:
creating build\temp.win-amd64-3.7\Release\dtaidistance
C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.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 Studio19\BuildTools\VC\Tools\MSVC.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\
仅安装 MSVC (1.8 GB) 后 - 仅此而已,作为测试以查看是否已经满足我的全部需求:
我们看到安装还是失败了,但是报错有点变化,现在至少ERROR: Failed building wheel for dtaidistance
已经消失了,看下面的截图:
creating build\temp.win-amd64-3.7\Release\dtaidistance
C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.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 Studio19\BuildTools\VC\Tools\MSVC.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.
在上面的 MS Visual++ 屏幕截图中的 MSVC 复选框正下方安装其他 4 个复选框后,我可以安装包。
也许将 python 设置中指定的 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64\cl.exe
更改为 MinGW gcc 编译器 C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\c++.exe
可能已经解决了?
这个想法没有机会了。
- MSVC
我已经向他们发送反馈,但我没有得到任何回复。一位 Python 开发人员保证他们无论如何都知道这个尺寸问题并且也不喜欢它。唯一的机会是 MSVC 开发人员自己进行更改。 MSVC 团队在未来的版本中不太可能(但并非不可能)缩小大小。
- 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 论坛:
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.
现在事实证明,distutils 不是一个现实的解决方法。
- 没有人会处理它。之前参与该项目的一位Python开发人员:也许有...
... someone else who might offer to help. But I wouldn’t be too optimistic.
- 还有一个弃用问题:
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.