简体   繁体   中英

Running pylint returns ModuleNotFoundError: No module named 'wrapt.wrappers'

I'm trying to use Visual Studio Code with pylint. When I load any .py file, I get the following error in the output console:

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'

This isn't specific to VS Code, I get the same result when running this command from commandline:

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's dependencies are installed:

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 32 bit on Win 10 64 bit. Python's path is set in the system's environment variables.

I had a same problem, with similar environment (win 10 64-bit, VSCode, Python 3.6.3). I downloaded all the files from wrapt github repo: https://github.com/GrahamDumpleton/wrapt/tree/master/src/wrapt then I put it in my wrapt folder.

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

now my linter is working.

Module wrapt was incorrectly installed so I uninstalled it. Reinstallation failed because pip couldn't handle a special character in a MSVC warning. (No idea how the installation was reported successful in the first place).

There is a bug in pip's handling of special characters in the console output. As a workaround, I've replaced line 73 in \\lib\\site-packages\\pip\\compat\\__init__.py

from:

return s.decode(sys.__stdout__.encoding)

to:

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

and ran python -m pip install pylint again. This time it worked.

you may have installed the pylint with sudo . Try installing for the user scope for eg pip install pylint --user

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