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

There's a large Python project I am working on with several C / C ++ extensions. Currently, every time I want to get the code running on a new computer, I have to download everything from the repository and then run python setup.py install

multiple times, once for each extension ... and that assuming the computer has C- compiler - If it doesn't, this is another extra step or two.

Is there a way that I could pre-compile all the C extensions so that when the repository is loaded onto a new computer, everything works right out of the box without having to separately install all those sub-components? I realize this might not work well (or at all?) On different platforms, but let me say that I pre-compiled things on a 64-bit Windows 8 machine and wanted to install it on a different 64-bit Windows 8 machine - is this possible? If so, how do I do it?

+3


source to share


1 answer


It is possible. You are asking about Building Embedded Distributions .

You can create a built distribution like this, for example:

python setup.py bdist

      

You can choose one of the following formats:

python setup.py bdist --format=wininst

      



  • zip

    zip file (.zip) [default]
  • wininst

    self-extracting ZIP file for Windows
  • msi

    Microsoft Installer

All this can be done with a standard module distutils

.

If you want to take a more modern approach and use it setuptools

, you can build Platform Wheels for Windows:

python setup.py bdist_wheel

      

The last thing you could do is create a file setup.py

for all your extensions together. Even if you only install the source distribution, there will be much less work for you. With assembly distribution, this will be just one step.

+1


source







All Articles