0

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?

EvgenKo423
  • 2,256
  • 2
  • 16
  • 23
maxbachmann
  • 2,862
  • 1
  • 11
  • 35
  • How do you 'ship' the Windows version? Is it just a zipped up collection of files, or is there some sort of installer program? – Adrian Mole Jul 04 '20 at 16:00
  • Oh yes I forgot to mention, that it is simply installed from pypi – maxbachmann Jul 04 '20 at 16:01
  • OK. Not sure how those things work. But you can build a "Setup.exe" file that will check for, and install, if necessary the latest VC redistributable. Or just give a link to the M/S page... – Adrian Mole Jul 04 '20 at 16:03
  • As far as I know when using the normal `pip install` it will simply download the wheel (basically a zip file with all the files of the library), but as far as I know does not allow me to run any code upon installation. Thats why I wondered whether it would be possible to add everything required into the wheel. – maxbachmann Jul 04 '20 at 16:09

1 Answers1

1

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.

EvgenKo423
  • 2,256
  • 2
  • 16
  • 23