运行pylint返回ModuleNotFoundError:没有名为' wrapt.wrappers'

时间:2017-11-26 12:51:36

标签: python pylint

我试图将Visual Studio代码与pylint一起使用。当我加载任何.py文件时,我在输出控制台中收到以下错误:

Linting with pylint failed.
You could either install the 'pylint' linter or turn it off in setings.json via "python.linting.pylintEnabled = false".
Error: Command failed: C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\python.exe -m pylint --msg-template='{line},{column},{category},{msg_id}:{msg}' --reports=n --output-format=text c:\Users\(...)\Desktop\Untitled-1.py
Traceback (most recent call last):
  File "C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pylint\__main__.py", line 7, in <module>
    pylint.run_pylint()
  File "C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pylint\__init__.py", line 12, in run_pylint
    from pylint.lint import Run
  File "C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pylint\lint.py", line 43, in <module>
    import astroid
  File "C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\site-packages\astroid\__init__.py", line 57, in <module>
    from astroid.nodes import *
  File "C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\site-packages\astroid\nodes.py", line 30, in <module>
    from astroid.node_classes import (
  File "C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\site-packages\astroid\node_classes.py", line 26, in <module>
    from astroid import decorators
  File "C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\site-packages\astroid\decorators.py", line 12, in <module>
    import wrapt
  File "C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wrapt\__init__.py", line 4, in <module>
    from .wrappers import (ObjectProxy, CallableObjectProxy, FunctionWrapper,
ModuleNotFoundError: No module named 'wrapt.wrappers'

这不是VS代码特有的,从命令行运行此命令时我得到相同的结果:

C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\python.exe -m pylint --msg-template='{line},{column},{category},{msg_id}:{msg}' --reports=n --output-format=text c:\Users\(...)\Desktop\Untitled-1.py

安装了pylint的依赖项:

PS C:\Users\(...)> & C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\python.exe -m pip install pylint
Requirement already satisfied: pylint in c:\users\(...)\appdata\local\programs\python\python36-32\lib\site-packages
Requirement already satisfied: six in c:\users\(...)\appdata\local\programs\python\python36-32\lib\site-packages (from pylint)
Requirement already satisfied: colorama; sys_platform == "win32" in c:\users\(...)\appdata\local\programs\python\python36-32\lib\site-packages (from pylint)
Requirement already satisfied: isort>=4.2.5 in c:\users\(...)\appdata\local\programs\python\python36-32\lib\site-packages (from pylint)
Requirement already satisfied: mccabe in c:\users\(...)\appdata\local\programs\python\python36-32\lib\site-packages (from pylint)
Requirement already satisfied: astroid>=1.5.1 in c:\users\(...)\appdata\local\programs\python\python36-32\lib\site-packages (from pylint)
Requirement already satisfied: lazy-object-proxy in c:\users\(...)\appdata\local\programs\python\python36-32\lib\site-packages (from astroid>=1.5.1->pylint)
Requirement already satisfied: wrapt in c:\users\(...)\appdata\local\programs\python\python36-32\lib\site-packages (from astroid>=1.5.1->pylint)

Python 3.6.3在Win 10 64位上的32位。 Python的路径在系统的环境变量中设置。

3 个答案:

答案 0 :(得分:1)

我有同样的问题,环境相似(赢得10位64位,VSCode,Python 3.6.3)。 我从wrapt github repo下载了所有文件: https://github.com/GrahamDumpleton/wrapt/tree/master/src/wrapt 然后我把它放在我的包装文件夹中。

    C:\Users\(...)\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wrapt\

现在我的linter工作了。

答案 1 :(得分:0)

模块包装未正确安装,因此我将其卸载。重新安装失败,因为pip无法处理MSVC警告中的特殊字符。 (不知道安装是如何报告成功的。)

pip在控制台输出中处理特殊字符时出现错误。作为解决方法,我已在\lib\site-packages\pip\compat\__init__.py

中替换了第73行

从:

return s.decode(sys.__stdout__.encoding)

为:

return s.decode(sys.__stdout__.encoding, "replace")

再次运行python -m pip install pylint。这次它奏效了。

答案 2 :(得分:0)

您可能已经用sudo安装了pylint。尝试为用户范围安装pip install pylint --user