PackageLoader issues

If you get a message like ImportError: cannot import name factorial (see or, this is due to a failure in a somewhat-magical mechanism that Scipy uses to import symbols into the top-level scipy module. Rather than, e.g., from scipy.x.y import *, it uses a Numpy mechanism called PackageLoader, which uses files in each submodule to know what symbols to import. Those files do seem to be making it into the py2exe distribution, but they're not getting used correctly. I'm not sure if the bug is scipy or py2exe.

A hackish workaround is to modify scipy/ to explicitly import the symbols you need, e.g., from scipy.misc import factorial.

Brian K. Boonstra

The problem

When using py2exe with scipy, you end with messages about missing modules. Some of them may not end up mattering (as in my case where scipy_base.add was missing) but others do, notably __cvs_version__ modules of some scipy packages, plus the cephes module.

The solution

You just need a few includes. Here is what I have:

excludes = []
includes = ["scipy.special.__cvs_version__", "scipy.linalg.__cvs_version__", "scipy.special.cephes"]

opts = {
    "py2exe": {


but if your code actually uses more of the scipy packages, you might need to add a few more __cvs_version__ entries.


ScipyImportProblems (last edited 2010-07-08 17:36:50 by KennethArnold)