Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Python Package requires Visual Studio Build Tools

From this previous SO question, I understand that some python packages rely on Visual Studio Build Tools to compile sources from C on Windows.

I want to avoid using python packages that require Visual Studio Build Tools in my open source projects. I do not want to force my open-source users to install Build Tools for my python app. This seems like a major decrease in usability and makes it harder to install.

How can I determine which open-source python packages require Visual Studio Build Tools? I have checked pypi.org and libraries.io, as well as looked at the requirements.txt in each package's GitHub repo. I cannot find any sort of requirement for Visual Studio Build Tools, but when I try pip install on the package, it says it requires Build Tools...

I did find this website of pre-compiled python libraries from another SO post. Is it safe to assume that any library on this list requires Build Tools? However, I'm assuming this list is not exhaustive. Is there a better source of information?

Please note that I'm NOT asking how to install Visual Studio Build Tools. Thanks in advance for any help!

like image 645
nareddyt Avatar asked Jun 07 '26 19:06

nareddyt


1 Answers

I posted this on Reddit and received the following answer, which I believe is correct. Feel free to add another answer if needed.

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/

Follow up on whether there is any way to detect the use of compilers in a arbitrary python package:

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

like image 102
nareddyt Avatar answered Jun 09 '26 08:06

nareddyt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!