victorlei / smop

Small Matlab to Python compiler
MIT License
1.08k stars 409 forks source link

SyntaxError: unqualified exec is not allowed in function 'recordtype' it contains a nested function with free variables #129

Closed scottstanie closed 6 years ago

scottstanie commented 6 years ago

Error in running or importing smop with python 2.7.5

$ smop test.m
Traceback (most recent call last):
  File "/home/scott/.local/bin/smop", line 11, in <module>
    load_entry_point('smop==0.41', 'console_scripts', 'smop')()
  File "/home/scott/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 476, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/scott/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2700, in load_entry_point
    return ep.load()
  File "/home/scott/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2318, in load
    return self.resolve()
  File "/home/scott/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2324, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/scott/.local/lib/python2.7/site-packages/smop/main.py", line 16, in <module>
    from . import parse
  File "/home/scott/.local/lib/python2.7/site-packages/smop/parse.py", line 7, in <module>
    from . import node
  File "/home/scott/.local/lib/python2.7/site-packages/smop/node.py", line 8, in <module>
    from . recipes import recordtype
  File "/home/scott/.local/lib/python2.7/site-packages/smop/recipes.py", line 128
    exec(template, namespace)
SyntaxError: unqualified exec is not allowed in function 'recordtype' it contains a nested function with free variables

$ smop --version
0.41

Anything weird about my setup? Or has this happened before?

victorlei commented 6 years ago

Thank you for reporting this bug. Could you attach test.m which reproduces the bug.

Thanks, Victor

scottstanie commented 6 years ago

hmm I actually can't get it to reproduce this bug now.. The "test.m" was actually a few different files that I swapped out, it seemed to be throwing this error for anything I tried.

I can close this if you'd like since I can't give you better directions right now.

Victordmdb commented 5 years ago

I'm getting the same issue:

git clone https://github.com/victorlei/smop
cd smop && git checkout tags/0.41
python setup.py install
smop smop/solver.m

On Python 2.7.5, CentOS Linux release 7.5.1804

Victordmdb commented 5 years ago

I got it to work by reverting to the old exec syntax at https://github.com/victorlei/smop/blob/master/smop/recipes.py#L128 exec(template, namespace) -> exec template in namespace

jahagirdar commented 5 years ago

@Victordmdb Thanks I was facing the same problem and making the change recommended by you fixed it. @victorlei can you reopen this ticket and see of the fix by @Victordmdb is good to go in the production code.

MrRedstoner commented 4 years ago

Just got this exact issue. Freshly installed SMOP on CentOS7 through pip, tried to translate https://github.com/MrRedstoner/rp2019/blob/master/matlab/Cvicenie2/bisekcia.m and got the error repeatedly. Manually modifying /usr/lib/python2.7/site-packages/smop/recipes.py to perform the change mentioned by @Victordmdb did stop this error, instead I got 2 token unused warnings, a lot of str in the console, and no new file has appeared in the directory