gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 04:23:27 25 4
gpt4 key购买 nike

来自 this previous SO question ,我知道一些 python 包依赖于 Visual Studio Build Tools 在 Windows 上从 C 编译源代码。

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

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

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

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

最佳答案

我在 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 :/

关于python - 检查 Python 包是否需要 Visual Studio 构建工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53984268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com