简体   繁体   中英

invalid syntax when run pylint

the following is the stack trace, please suggest my python version is 2.7

-----------------
pylint
Traceback (most recent call last):
  File "E:\Python27\Scripts\pylint-script.py", line 11, in <module>
    load_entry_point('pylint==2.0.0', 'console_scripts', 'pylint')()
  File "E:\Python27\lib\site-packages\pylint-2.0.0-py2.7.egg\pylint\__init__.py"
, line 17, in run_pylint
    from pylint.lint import Run
  File "E:\Python27\lib\site-packages\pylint-2.0.0-py2.7.egg\pylint\lint.py", li
ne 75, in <module>
    import astroid
  File "E:\Python27\lib\site-packages\astroid-2.0.1-py2.7.egg\astroid\__init__.p
y", line 59, in <module>
    from astroid.exceptions import *
  File "E:\Python27\lib\site-packages\astroid-2.0.1-py2.7.egg\astroid\exceptions
.py", line 13, in <module>
    from astroid import util
  File "E:\Python27\lib\site-packages\astroid-2.0.1-py2.7.egg\astroid\util.py",
line 148
    yield from islice(iterator, size)
             ^
SyntaxError: invalid syntax
  1. my python version is 2.7

pylint 2.0.0 requires at least Python 3.4. 1

The last version that supported Python 2.7 was 1.9.2 . So, your fix is to downgrade to 1.9.2.


The specific error message you're seeing is because yield from was added to the language in Python 3.3, so code that uses it can't run in 2.7. But there are probably lots of other errors. After all, the only reason developers drop 2.7 support is so they can use new language features.


If you install it with pip install pylint or py -m pip install pylint using Python 2, it should automatically install 1.9.2 instead of 2.0.0—or, failing that, the installation should fail instead of appearing to succeed. (When I test it myself, that's exactly what happens.)

However, installing with an old version of pip , might cause this problem. If so, upgrade your pip and setuptools . (You definitely want at least pip 10 and setuptools 30… but generally you want the latest version available, so just let it do that.)

py -m pip install --upgrade pip setuptools

If that was your problem, you should have seen a warning, like You are using pip version 6.0, however version 18.0 is available. That warning doesn't look hugely important, but it is—especially if you're staying on 2.7 (or, similarly, if you like to follow the bleeding edge and install beta versions of Python).

Installing with easy_install can definitely cause this. If that's your problem, just stop using easy_install and start using pip .

If you installed it manually instead of by using pip , then you have to do the version checking manually as well. If you have a good reason for doing that, download 1.9.2 and install that manually instead.


At any rate, however you got thing into this situation, you should be able to fix it by uninstalling pylint and then running:

py -m pip install pylint==1.9.2

1. According to its own documentation, it specifically supports 3.4, 3.5, and 3.6. It may also support 3.7 despite saying it doesn't—later versions definitely do, and of course future versions will support even newer versions of Python. But definitely not 2.7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM