Compiling one SciPy module into * .pyd

I am developing a small tool that uses mostly NumPy and one SciPy module (scipy.optimize.fsolve). My idea to share it with others is that it comes bundled with Portable Python so that in theory anyone can run it.

The entire SciPy package weighs a lot (about 80 MB). Is it possible to compile only 1 module into * .pyd and import it like any other module so that I don't have to include modules that I really don't need?

+3


source to share


1 answer


There are several possibilities if you want to distribute only SciPy subset code with your code (and in particular scipy.optimize.fsolve

),

  • Look at the SciPy source code and copy only the files needed for the function fsolve

    . After a quick glance, that would, at least scipy/optimize/optimize.py

    , scipy/optimize/minpack.py

    , scipy/optimize/_minpack.so/.pyd

    (but maybe I missed a couple).
  • In a simplified approach, delete the folder by folder unused parts catalog scipy installation (especially those that occupy a lot of space), including scipy/weave

    , scipy/sparse

    , scipy/linalg

    , etc.
  • Write a simple wrapper around scipy.optimize.fsolve

    and compile it to C code with cython, this should create an independent .pyd / .so


There must be a python module for this, for example pyinstaller

contains only the necessary modules in an executable binary executable. Thus, you will need an equivalent pyinstaller

that creates dynamic libraries.

+2


source







All Articles