【发布时间】:2020-06-06 12:47:52
【问题描述】:
我正在尝试使用 GCC 而不是 MS C++ 构建工具在我的 Windows 机器上构建 Python 包,前者要小得多(尽管仍然是 1.5GB)。
我已经使用MSYS2 设置了mingw-w64,它在路径中,所以:
C:\Users\username>where g++
c:\MyPrograms\msys64\mingw64\bin\g++.exe
C:\Users\username>g++ --version
g++ (Rev3, Built by MSYS2 project) 10.1.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
到目前为止,一切都很好。
我如下设置distutils.cfg,如here所述:
[build]
compiler=mingw32
[build_ext]
compiler=mingw32
但随后安装诸如astropy 之类的包会产生以下错误:
ValueError: Unknown MS Compiler version 1916
我在某处看到了填写 distutils.cfg 的建议,如下所示:
[build]
compiler=g++
[build_ext]
compiler=g++
然后引发:
error: don't know how to compile C/C++ code on platform 'nt' with 'g++' compiler
有什么想法吗?
编辑:完整跟踪
running build_ext
running pre_hook from astropy.modeling.setup_package for build_ext command
running pre_hook from astropy._erfa.setup_package for build_ext command
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\username\AppData\Local\Temp\pip-install-id1zp2pt\astropy\setup.py", line 35, in <module>
setup(setup_requires=setup_requires)
File "c:\users\username\appdata\local\temp\pip-install-id1zp2pt\astropy\astropy_helpers\astropy_helpers\setup_helpers.py", line 102, in setup
setuptools_setup(**package_info)
File "c:\users\username\appdata\local\programs\python\python38\lib\site-packages\setuptools\__init__.py", line 161, in setup
return distutils.core.setup(**attrs)
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\users\username\appdata\local\programs\python\python38\lib\site-packages\setuptools\command\install.py", line 61, in run
return orig.install.run(self)
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\command\install.py", line 545, in run
self.run_command('build')
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\users\username\appdata\local\temp\pip-install-id1zp2pt\astropy\astropy_helpers\astropy_helpers\setup_helpers.py", line 298, in run
orig_run(self)
File "c:\users\username\appdata\local\temp\pip-install-id1zp2pt\astropy\astropy_helpers\astropy_helpers\commands\build_ext.py", line 142, in run
super().run()
File "c:\users\username\appdata\local\programs\python\python38\lib\site-packages\setuptools\command\build_ext.py", line 87, in run
_build_ext.run(self)
File "c:\users\username\appdata\local\programs\python\python38\lib\site-packages\Cython\Distutils\old_build_ext.py", line 186, in run
_build_ext.build_ext.run(self)
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\command\build_ext.py", line 306, in run
self.compiler = new_compiler(compiler=self.compiler,
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\ccompiler.py", line 1032, in new_compiler
return klass(None, dry_run, force)
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\cygwinccompiler.py", line 282, in __init__
CygwinCCompiler.__init__ (self, verbose, dry_run, force)
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\cygwinccompiler.py", line 157, in __init__
self.dll_libraries = get_msvcr()
File "c:\users\username\appdata\local\programs\python\python38\lib\distutils\cygwinccompiler.py", line 86, in get_msvcr
raise ValueError("Unknown MS Compiler version %s " % msc_ver)
ValueError: Unknown MS Compiler version 1916
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\username\appdata\local\programs\python\python38\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\username\\AppData\\Local\\Temp\\pip-install-id1zp2pt\\astropy\\setup.py'"'"'; __file__='"'"'C:\\Users\\username\\AppData\\Local\\Temp\\pip-install-id1zp2pt\\astropy\\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\username\AppData\Local\Temp\pip-record-zwu6d9vh\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\username\appdata\local\programs\python\python38\Include\astropy' Check the logs for full command output.
【问题讨论】:
-
您已经设置了 MSYS2,但您正在运行命令提示符中的命令。为什么不使用 MSYS2 shell?
-
因为无法从 MSYS2 shell 安装 Python 包...
-
我之前在MSYS2下搭建并安装过Python包...
-
请注意,我并没有尝试在 MSYS2 中包含的 python 发行版中安装软件包。我只是使用 MSYS2 来获取最新的 mingw-w64 工具链。
-
我有一个个人构建的 MinGW-w64,你可以在没有 MSYS2 的情况下获得它。签出:winlibs.com