469,903 Members | 1,499 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Embedded Python application don't work if Python is installed

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.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@zoran.com>
http://tebeka.spymac.net
The only difference between children and adults is the price of the toys
Jul 18 '05 #1
2 2077
"Miki Tebeka" <mi*********@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
__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
Jul 18 '05 #2
Hello Thomas,
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)
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.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@zoran.com>
http://tebeka.spymac.net
The only difference between children and adults is the price of the toys
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Alexander May | last post: by
6 posts views Thread by Farshid Lashkari | last post: by
3 posts views Thread by Matthias Baas | last post: by
68 posts views Thread by Lad | last post: by
20 posts views Thread by Jack | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.