Embedded Python application don't work if Python is installed

Thomas Heller theller at python.net
Tue Jul 6 19:08:45 CEST 2004

"Miki Tebeka" <miki.tebeka at zoran.com> writes:

> Hello All,
> I have a funny problem:
> An embedded python application is working fine on a "clean" computer.
> When it runs on a computer with python installed (the very same computer
> used to produce the application) it has a import error:
> ----------
> can't import SACD module (sacd.py)
> Error in sys.exitfunc:
> Traceback (most recent call last):
>   File "atexit.pyc", line 20, in _run_exitfuncs
>   File "threading.pyc", line 566, in __exitfunc
>   File "threading.pyc", line 578, in _pickSomeNonDaemonThread
>   File "c:\ADP86Tools\bin\sacd.py", line 44, in ?
>     filterwarnings("ignore", category=FutureWarning)
>   File "warnings.pyc", line 140, in filterwarnings
>   File "re.pyc", line 5, in ?
>   File "sre.pyc", line 97, in ?
>   File "sre_compile.pyc", line 13, in ?
>   File "_sre.pyc", line 9, in ?
>   File "_sre.pyc", line 7, in __load
> ImportError: DLL load failed: The specified module could not be found.
> ----------
> (The traceback is printed from the embedding application)

No solution, but hopefully some hints how to approach this.

First, but maybe you have seen this already, isn't the real problem that
SACD cannot be imported? Where is the traceback for that?
The traceback above imo only shows that there's a problem shutting down
the application.  The top frame refers to atexit running the exitfuncs.
The last frame shows that py2exe imports extension modules (_sre.pyd in
this case, required by warnings as it seems) in a different way: via a
small python loader, named _sre.py(c), in the library.zip file.
You can look up the loaders sourcecode in py2exe\build_exe.py, the
template is this:
LOADER = """
def __load():
    import imp, os, sys
    dirname = sys.prefix
    path = os.path.join(dirname, '%s')
    #print "py2exe extension module", __name__, "->", path
    mod = imp.load_dynamic(__name__, path)
##    mod.frozen = 1
del __load
This is because the *only* item on sys.path is the library.zip file.
So, it seems that your exitfunc tries to print a warning, and cannot,
because it cannot import _sre.pyd any more (maybe because Python has
shut down partly?).

Second, you say the problem only shows up on a computer where python is
installed.  To track down this, you can define a PY2EXE_VERBOSE
environment variable before running the exe - this has the same effect
as the PYTHONVERBOSE env var, or the -v flag, for normal Python: it
traces import statements to the console.

Hopefully this helps you to find out the different behaviour in both


More information about the Python-list mailing list