cloudmatrix / esky

an auto-update framework for frozen python apps
BSD 3-Clause "New" or "Revised" License
363 stars 74 forks source link

Unqualified exec is not alllowed (from f_py2exe.py) #107

Closed AnthonyFloyd closed 8 years ago

AnthonyFloyd commented 8 years ago

Python 2.7.5, esky 0.9.9, py2exe 0.6.9 on Win32

When we run setup, we get an error immediately after the data files get copied to the dist directory:

error: compiling '__main__.py' failed`
    SyntaxError: unqualified exec is not allowed in function '_chainload' it contains a nested function with free variables (__main__.py, line 838)`

So I dug into f_py2exe.py and pulled out the __main__.py that is being generated. Line 838 is in load_resource():

for code in codelist:
    exec(code, d_globals, d_locals)`

Digging even further in, it seems this is a difference in how Python 3.x handles exec() vs how Python 2.x handles exec().

After consulting the Python 2.x documentation page for the exec statement, changing those lines to:

for code in codelist:
    exec code in d_globals, d_locals

fixed the problem. Mind you the same doc page says that exec(expr, globals, locals) is equivalent to exec expr in globals, locals but clearly it's not.

timeyyy commented 8 years ago

same issue as #99

@AnthonyFloyd david gave a patch in the following but i haven't got around to implementing it, would you be able to make a pull request?