I am trying to run py2exe and minimize the third-party dependencies. I'm trying to include only the small necessary part of a huge third-party package but can't figure out how to prevent the package's __init__.py
, which imports a whole lot of stuff I don't want, from being called at runtime.
This summarizes the situation:
myscript.py: from BigPackage.SmallSubset import TheOnlyFunctionIReallyNeed
BigPackage/__init__.py: import SmallSubset, HugeUnwantedSubset
BigPackage/SmallSubset.py: import AcceptableDependencies
BigPackage/HugeUnwantedSubset.py: import UnacceptablyHugeDependencies
The problem is that, even if I successfully include some parts of BigPackage
but not others, when import BigPackage.SmallSubset
is called at runtime, BigPackage/__init__.py
runs first, which then tries to import the excluded parts and hence raises an exception. It would work if I could persuade py2exe to include BigPackage/SmallSubset.py
but not BigPackage/__init__.py
, but I'm having no luck getting py2exe to understand that idea. I've tried the following in my setup.py
:
import BigPackage # let's try a Deny/Allow approach:
options[ 'py2exe' ][ 'excludes' ].append( 'BigPackage' )
options[ 'py2exe' ][ 'includes' ].append( 'BigPackage.SmallSubset' )
# nope, py2exe fails with 'ImportError: No module named BigPackage' in py2exe/mf.py
...and/or:
import BigPackage # this seems less plausible, but worth a try:
options[ 'py2exe' ][ 'excludes' ].append( 'BigPackage.__init__' )
# nope, __init__.pyc still turns up in dist
...and/or:
import BigPackage # really getting desperate now:
options[ 'py2exe' ][ 'excludes' ].append( BigPackage.__file__ )
# nope, __init__.pyc still turns up in dist
... with no luck. Anybody know how to work around this?