How to ensure the MSVC++ Redistributable is available on user's system?

Question:

I wrote a Python library in C++14. Since users often do not have a C++ compiler installed, I create wheels for Linux, Windows and macOS and upload those to PyPI. While this works fine for Linux and macOS, on Windows it is required to install the Microsoft Visual C++ Redistributable for Visual Studio 2015/2017/2019. When that’s not done the user will only get a runtime error telling him that it failed to import the DLL.

Is there a way to add it into the wheels, automatically install it, or at least to give the user a warning telling him what exactly he has to do to get it to work?

Asked By: maxbachmann

||

Answers:

First of all, you could eliminate this problem completely by simply building your extension module with the same compiler version that was used for the lowest version of Python you want to support. MSVC++ Redis­trib­ut­ables get installed with Python as well and are backward-compatible down to VC++ 2015.

If the above is not an option, you could wrap your extension module into a Python package and use the package_data option to include the redis­trib­ut­able files, but Microsoft doesn’t recommend this.

Instead, you could handle things at import time, similarly to how PyTorch does this. Specifically, try to import the extension module into a package and if it will fail either try to download and install the redis­trib­ut­able on your own (requires an administrator rights) or ask user to do so.

Answered By: EvgenKo423