安装pymysql报错:File "/usr/local/lib/python2.7/site-packages/PyMySQL-1.0.2-py2.7.egg/pymysql/connections.py", line 167 SyntaxError: invalid syntax

 

Traceback (most recent call last):
  File "log2user-real.py", line 49, in <module>
    db = create_engine("mysql+pymysql://root:{m_pass}@10.157.2.25:8306/log_user?charset=utf8".format(m_pass=m_pass))
  File "<string>", line 2, in create_engine
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/create.py", line 548, in create_engine
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/pymysql.py", line 68, in dbapi
    return __import__("pymysql")
  File "build/bdist.linux-x86_64/egg/pymysql/__init__.py", line 59, in <module>
  File "/usr/local/lib/python2.7/site-packages/PyMySQL-1.0.2-py2.7.egg/pymysql/connections.py", line 167
    *,
     ^
SyntaxError: invalid syntax

原因:PyMySQL的最新版,不支持Python 2.7

解决方法:指定PyMySQL版本为0.10.1,requirements.txt文件中写入:PyMySQL==0.10.1

pip install pymysql==0.10.1

参考:https://github.com/PyMySQL/PyMySQL/blob/master/CHANGELOG.md

posted @ 2022-12-03 16:06  JeromePowell  阅读(443)  评论(0编辑  收藏  举报