Tag Archives: SyntaxError: invalid syntax

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

raceback (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
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

[Python] error syntax error: summary of solutions to invalid syntax

Today, I learned Python, but I had a problem at the beginning. The code was perfectly fine, but every time I ran it, it showed “SyntaxError: Invalid Syntax”.

“SyntaxError: invalid syntax” means “mark> syntax error ;
after query solved the problem, so concluded a solution to this question:

    version problem:
    because python2 and python3 are incompatible, so some can run on python2 code can not run on python3; You can try to change versions; path problem:
    remember to take a closer look at your own path is correct; careless problem: br> f>t to add colon (:) at the end of if, elif, else, for, while, class,def declarations;
    used = instead of ==; When installing third-party modules :
    when installing third-party modules is also likely to be “SyntaxError: invalid syntax” this problem, then need to check some is installed under the CMD window, at the same time, to the python installation directory, find PIP installation directory inside;