generated app fails due to syntax error

Issue #70 resolved
Luc Jean
created an issue


I have an app which is running ok when started from Python. I would like to use pyapp for packaging it on MAC OS 10.6.8.

The app is a small embedded webapp running with bottle microframework. It has been packages successfully on windows with py2exe.

I have the following py2app script

from setuptools import setup
import sys, os, os.path
wapp_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))



    app = [
            'argv_emulation': True, 
            "includes":["shelve", "dbhash", "sqlite3", "waitress", "runpy_imports", "bottle_sqlalchemy"],
            "packages": ["sqlalchemy.dialects.sqlite", "sqlalchemy.util", "nsav_wapp"],

The py2app seems to be ok. I've a generated app file and I can see that it contains the right code.

Unfortunately, the app fails on startup. Here is the traceback:

25/10/12 16:55:53   [0x0-0x118118].org.pythonmac.unspecified.nsav_ws[5126]  argvemulator warning: fetching events failed
25/10/12 16:55:53   [0x0-0x118118].org.pythonmac.unspecified.nsav_ws[5126]  Traceback (most recent call last):
25/10/12 16:55:53   [0x0-0x118118].org.pythonmac.unspecified.nsav_ws[5126]    File "/Users/luc/Dev/nelly_signe_avec_vous/nsav/nsav_mac/dist/", line 340, in <module>
25/10/12 16:55:53   [0x0-0x118118].org.pythonmac.unspecified.nsav_ws[5126]      _run()
25/10/12 16:55:53   [0x0-0x118118].org.pythonmac.unspecified.nsav_ws[5126]    File "/Users/luc/Dev/nelly_signe_avec_vous/nsav/nsav_mac/dist/", line 311, in _run
25/10/12 16:55:53   [0x0-0x118118].org.pythonmac.unspecified.nsav_ws[5126]      exec(compile(source, path, 'exec'), globals(), globals())
25/10/12 16:55:53   [0x0-0x118118].org.pythonmac.unspecified.nsav_ws[5126]    File "/Users/luc/Dev/nelly_signe_avec_vous/nsav/nsav_mac/dist/", line 2
25/10/12 16:55:53   [0x0-0x118118].org.pythonmac.unspecified.nsav_ws[5126]      
25/10/12 16:55:53   [0x0-0x118118].org.pythonmac.unspecified.nsav_ws[5126]      ^
25/10/12 16:55:53   [0x0-0x118118].org.pythonmac.unspecified.nsav_ws[5126]  SyntaxError: invalid syntax
25/10/12 16:55:53   nsav_ws[5126]   nsav_ws Error

Is it a bug or a mistake in my use of py2app?

Thanks in advance Best luc

Comments (11)

  1. Ronald Oussoren repo owner

    I have no idea why it won't work. I'm assuming it works fine from the commandline given that your script works on Windows.

    Something you could try to do is check if the problem is also present when you load your script the same way as py2app does:

    script = open("").read()
    code = compile(script, "", "exec")
    exec(code, globals(), globals())

    If that doesn't give a clue: could you try to create a sample project that demonstrates the problem by removing as much of the contents of as possible (leaving just enough to cause the problem, without having to share all your code).

    (formatting code should be possible with a block where the line before the block ends with a colon and the code block itself is indented 4 spaces)

  2. Ronald Oussoren repo owner

    Something else you could check:

    • py2app copies your script into the application bundle as Does that script have the right contents?

    • check that are no strange characters on the second line:

      script = open("").read()
      print repr(script)

    Then check for unexpected text on the first few lines (all \x escapes would be suspect)

  3. Luc Jean reporter

    Thanks for your ideas:

    The following code is causing a similar problem:

    script = open("").read()
    code = compile(script, "", "exec")
    exec(code, globals(), globals())

    It seems that this is cause by windows type of line ending "\r\n". If i switch to unix type "\n", the code below works ok.

    Is it something normal?

  4. Luc Jean reporter

    Executing the code with exec is ok. It runs the app without any problem.

    However, it is still not working with py2app. The app fails with nsav_ws Error.

    I've made a simple example with bottle and it runs ok.

    In the traceback an error is raise in sqlalchemy:

        26/10/12 22:59:17   [0x0-0x5d05d].org.pythonmac.unspecified.nsav_ws[1079]     File "sqlalchemy/__init__.pyc", line 12, in <module>
        26/10/12 22:59:17   [0x0-0x5d05d].org.pythonmac.unspecified.nsav_ws[1079]     File "sqlalchemy/sql/__init__.pyc", line 7, in <module>
        26/10/12 22:59:17   [0x0-0x5d05d].org.pythonmac.unspecified.nsav_ws[1079]     File "sqlalchemy/sql/expression.pyc", line 32, in <module>
        26/10/12 22:59:17   [0x0-0x5d05d].org.pythonmac.unspecified.nsav_ws[1079]   ImportError: cannot import name util

    I've opened the package and there is a util.pyc in sqlalchemy.sql. Any idea what can be wrong?

    Thanks for your precious help

  5. Ronald Oussoren repo owner

    Windows line endings cause problems with compile() when using python 2.6. I've updated the py2app sources for this.

    I don't understand the sqlalchemy problem, sqlalchemy should work just fine.

  6. Ronald Oussoren repo owner

    The SQLAlchemy problem could be caused by your file. Could you change the packages option to "packages = ['sqlalchemy']"? That will include all of SQLAlchemy.

  7. Log in to comment