Embedded Python application don't work if Python is installed

M

Miki Tebeka

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)

All the required modules are in a library (python23.zip) and placed
the needed dll's in the same directory as the application (it's in
sys.path).
The script itself is a regular python file (.py), dependencies were found
using py2exe.

OS is win2k and Python is 2.3.4.

I've tried editing sys.path to contain only the application directory and
the library zip and also to add the application directory to PATH
environment variables. Nothing helps.

The offending module is re. Writing
import re
re.compile("\s+")
will cause the same problem.

Any ideas?

Bye.
 
T

Thomas Heller

Miki Tebeka said:
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.

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
__load()
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
cases.

Thomas
 
M

Miki Tebeka

Hello Thomas,
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 SACD module can be imported on a machine without Python installed and
it's working.
The traceback above imo only shows that there's a problem shutting down
the application.
The application is shutting down since SACD can't be imported.
This is because the *only* item on sys.path is the library.zip file.
Nope, printing sys.path showed that all the "regular" Python path is in.
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.
This is *not* a python script wrapped with py2exe. py2exe was
used only to find the dependencies and create the zip file (which was
renamed to python23.zip).

I've found out that if I remove the _sre.pyd and the zip library everything
works on a computer with Python installed. However I'm still in the dark on
how to solve this.

Thanks for your time.

Bye.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top