Embedded Python application don't work if Python is installed

Discussion in 'Python' started by Miki Tebeka, Jul 5, 2004.

  1. Miki Tebeka

    Miki Tebeka Guest

    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 <>
    http://tebeka.spymac.net
    The only difference between children and adults is the price of the toys
    Miki Tebeka, Jul 5, 2004
    #1
    1. Advertising

  2. "Miki Tebeka" <> 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
    Thomas Heller, Jul 6, 2004
    #2
    1. Advertising

  3. Miki Tebeka

    Miki Tebeka Guest

    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 <>
    http://tebeka.spymac.net
    The only difference between children and adults is the price of the toys
    Miki Tebeka, Jul 7, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Learner
    Replies:
    4
    Views:
    2,053
    Learner
    Jan 27, 2006
  2. Rhino
    Replies:
    3
    Views:
    376
    Mark Thornton
    Apr 10, 2004
  3. Gregoire Banderet
    Replies:
    0
    Views:
    361
    Gregoire Banderet
    Jan 15, 2004
  4. Replies:
    3
    Views:
    424
    Jason
    Apr 28, 2008
  5. KillSwitch
    Replies:
    3
    Views:
    373
    Gabriel Genellina
    Oct 28, 2009
Loading...

Share This Page