I want to create a pip-installable (this is important, we already have a mostly-working easy-install version, but we want to switch to PIP) python package, which is essentially a wrapper for some C functions. As I understand it, I cannot count on users having compilers installed (e.g. Windows), and so preferably I would precompile these files and upload them onto a server. What I would like, is PIP to download a suitable file (I would prefer if it wasn't necessary for all these files to come shipped with the package) during the installation. I've tried reading the docs, but failed to find any solutions for my problem there. Is PIP able to download a compiled C file from a server during the installation? If so, what is the course of action? Should I perhaps try to include a python script, to be run at installation, which would determine the OS and the architecture, and then access a specific link?
-
https://packaging.python.org/guides/packaging-binary-extensions/ – phd Oct 16 '19 at 13:58
-
do you have an index like pyPI that you will serve the package from, or how will users download/access the package? – Arne Oct 17 '19 at 07:21
1 Answers
You are correct in most of your assumptions. You can offer a source distribution, or sdist
, which requires build tools on the target machine in order to be installed. It is often uploaded as a fallback when the platform wheel that you need doesn't exist, or if you want your users to be able to build it themselves.
Speaking of wheels, that is the name of the current standard for binary python distributions, or bdist
s. If your package contains code that needs to be compiled, wheels will end up being platform specific - depending on the used build system that can be Linux
, macOS
, or Windows
. See for example the sklearn
entry on pyPI, which features one wheel per os for all supported python versions (plus 32/64 bit support, but that's another story).
If you specify an index (or just a directory that has the wheels in it) where pip should install from, it will automatically make sure that it downloads/installs the correct wheel, which avoids writing platform-specific code into your source code. The hard part is building the wheels.
Related question:
- Pip install and platform specific wheels
- How to avoid building C library with my python package? (ends up building platform specific wheels)

- 17,706
- 5
- 83
- 99