3
votes

I'm developing a small tool which uses mainly NumPy and one SciPy module (scipy.optimize.fsolve). My idea of sharing it with others is that it comes in package with Portable Python so that theoretically everyone can run it.

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

1

1 Answers

2
votes

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

  1. Look at the SciPy source code and copy only the files that are needed for the fsolve function. After a quick glance that would be at least, scipy/optimize/optimize.py, scipy/optimize/minpack.py, scipy/optimize/_minpack.so/.pyd (but maybe I missed a couple).
  2. In simpler approach, remove folder by folder unused parts in the scipy install directory (particularly those that take a lot of space), including scipy/weave, scipy/sparse, scipy/linalg etc.
  3. Write a simple wrapper around the scipy.optimize.fsolve and compile it to C code with cython, this should produce an independent .pyd/.so

There should be a python module to do this automatically, for instance pyinstaller does include only the required modules in the binary executable it produces. So you would need an equivalent of pyinstaller that produces dynamic libraries.