pymysql Error: File “/usr/local/lib/python2.7/site-packages/PyMySQL-1.0.2-py2.7.egg/pymysql/”, line 167 SyntaxError: invalid syntax

raceback (most recent call last):
  File "", line 49, in <module>
    db = create_engine("mysql+pymysql://root:{m_pass}@".format(m_pass=m_pass))
  File "<string>", line 2, in create_engine
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/", line 309, in warned
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/", line 548, in create_engine
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/", line 68, in dbapi
    return __import__("pymysql")
  File "build/bdist.linux-x86_64/egg/pymysql/", line 59, in <module>
  File "/usr/local/lib/python2.7/site-packages/PyMySQL-1.0.2-py2.7.egg/pymysql/", line 167
SyntaxError: invalid syntax
Reason: The latest version of PyMySQL does not support Python 2.7

Solution: Specify the PyMySQL version as 0.10.1, and write in the requirements.txt file:PyMySQL==0.10.1

pip install pymysql==0.10.1

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *