johnny_be
johnny_be

Reputation: 319

Is it possible to pre-compile (pre-build/pre-install) a Python C/C++ extension?

There's a large Python project that I'm working on with several C/C++ extensions. Currently, every time I want to get the code running on a new machine, I have to download everything from the repository and then run python setup.py install several times, once for each extension... and that's assuming the computer has a C compiler installed--if it doesn't, that's another extra step or two.

Is there any way that I could pre-compile all of the C extensions so that when I download the repository to a new machine, everything works right out of the box without having to separately install all of these sub-components? I understand that this may not work well (or at all?) across different platforms, but let's say I pre-compiled things on a 64-bit Windows 8 machine and wanted to install it on another 64-bit Windows 8 machine--is that possible? If so, how would I go about doing it?

Upvotes: 5

Views: 1020

Answers (1)

tynn
tynn

Reputation: 39853

It is possible. You are asking about Creating Built Distributions.

You can create such a built distribution like:

python setup.py bdist

You can even choose between different formats like:

python setup.py bdist --format=wininst
  • zip zip file (.zip) [default]
  • wininst self-extracting ZIP file for Windows
  • msi Microsoft Installer

All this you can do with the standard distutils module.

If you would like to use a more modern approach and use setuptools, it is possible to build Platform Wheels for Windows:

python setup.py bdist_wheel

A last thing you could do is creating a setup.py file for all your extensions together. Even if you are only installing a source distribution, it would be much less work for you to do. With a build distribution it would be only one step to perform.

Upvotes: 1

Related Questions