检查 Python 包是否需要 Visual Studio 构建工具

Check if Python Package requires Visual Studio Build Tools

,我了解到一些 python 软件包依赖 Visual Studio 构建工具来编译 Windows.

上的 C 源代码

我想避免在我的开源项目中使用需要 Visual Studio 构建工具的 python 包。我不想强迫我的开源用户为我的 python 应用程序安装构建工具。这似乎是可用性的重大下降,并且更难安装。

如何确定哪些开源 python 包需要 Visual Studio 构建工具? 我已经检查了 pypi.org 和 libraries.io,并查看了每个包的 GitHub 存储库中的 requirements.txt。我找不到 Visual Studio Build Tools 的任何类型的要求,但是当我在包上尝试 pip install 时,它说它需要 Build Tools...

我确实从另一个 SO post 中找到了 this website of pre-compiled python libraries。假设此列表中的任何库都需要构建工具是否安全?但是,我假设此列表并不详尽。有没有更好的信息来源?

请注意,我不是在询问如何安装 Visual Studio 构建工具。在此先感谢您的帮助!

我在 Reddit 上发布了这个并收到了以下答案,我认为这是正确的。如果需要,请随时添加其他答案。

Basically the answer is any time a package must compile C code to build. It's not obvious looking at a packages requirements because the build commands provided by setup tools automatically look for Visual Studio on Windows.

In the distutils configuration file you can set the compiler of your choice: https://docs.python.org/3/install/index.html#using-non-microsoft-compilers-on-windows . And then when installing via pip you can choose the --no-binary options to make sure you don't get binaries pre-compiled by Visual Studio: https://pip.pypa.io/en/stable/reference/pip_install/#cmdoption-no-binary

You might also be interested in conda-forge which provides an open source way of providing many package binaries via the conda package manager: https://conda-forge.org/

跟进是否有任何方法可以检测任意python包中使用编译器:

I assume a lot of packages will have distutils.core.Extension called at some point in their setup.py: https://docs.python.org/3/extending/building.html#building-c-and-c-extensions-with-distutils

Though setup.py allows you to call arbitrary Python code so the actual C compilation could be hidden somewhere completely different or even use an entirely different build process.

Basically if the license or adherence to FOSS principles it important to your application you either need to base your dependency chain on work other people have already done (e.g. conda-forge) or you need to spend time really investigating the status of every dependency you use :/