sqlalchemy: `from sqlalchemy import create_engine` import error

Describe the bug Getting the following when importing 1.4.0 sqlalchemy’s create_engine method:

Python 2.7.5 (default, Aug  7 2019, 00:51:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sqlalchemy import create_engine
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/__init__.py", line 9, in <module>
    from .engine import create_engine
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 18, in <module>
    from . import events
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/events.py", line 9, in <module>
    from .base import Engine
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 12, in <module>
    from .interfaces import Connectable
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/interfaces.py", line 11, in <module>
    from ..sql.compiler import Compiled  # noqa
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/sql/__init__.py", line 13, in <module>
    from .expression import Alias
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/sql/expression.py", line 144, in <module>
    from .lambdas import lambda_stmt
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/sql/lambdas.py", line 1067
    exec(code, vars_, vars_)
SyntaxError: unqualified exec is not allowed in function '_rewrite_code_obj' it contains a nested function with free variables

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 23 (16 by maintainers)

Commits related to this issue

Most upvoted comments

glad we could figure this out thanks all for the help!

@zzzeek See #6112 for a pull request. I’m not sure though how to provide a meaningful test for this, without having a test executor that also runs python 2.7.5. Please advise what you need there.

Hi @zzzeek I have the similar importError problem with python3.9.1 and sqlalchemy 1.4. BTW, with sqlalchemy 1.3.23 it’s OK.

you have a different problem. you seem to be using this package which is apparently not working for SQLAlchemy 1.4 . I would report this on their issue tracker at https://github.com/encode/databases .