Skip to content

Pylint not working when in pipenv virtualenv #18802

Closed

Description

Discussed in #18787

Originally posted by bmarden March 26, 2022
I think this is a bug, but I'm not sure so posting in Q&A

When I try to use pylint in a virtual environment using pipenv, pylint fails with the error below. When using my globally installed version of pylint, it works correctly.

Vscode output tab:

> ~/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/bin/python ~/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/linter.py -m pylint ./main.py
cwd: .
##########Linting Output - pylint##########


[ERROR 2022-2-26 19:34:41.31]: Linter 'pylint' failed to parse the output '. SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at s.parseMessages (/Users/bmarden/.vscode/extensions/ms-python.python-2022.0.1814523869/out/client/extension.js:78:360175)
    at s.run (/Users/bmarden/.vscode/extensions/ms-python.python-2022.0.1814523869/out/client/extension.js:24:218086)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at s.runLinter (/Users/bmarden/.vscode/extensions/ms-python.python-2022.0.1814523869/out/client/extension.js:78:359692)

If I run the pylint command in the terminal, it works correctly

~/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/bin/python -m pylint ./main.py

I have the following workspace settings:

{
  "python.linting.pylintEnabled": true,
  "python.linting.enabled": true,
}

I've also tried using the pre-release version and the previous version, v2022.0.1814523869, of the python extension.

Any help would be greatly appreciated. Thank you!

System information

  • MacOS Monterey 12.3
  • python 3.10.2 via homebrew

Activity

  1. karthiknadig commented on Mar 29, 2022

    @karthiknadig
    Member

    Ben Marden (@bmarden) Can you run this directly in the terminal and share the output:

    ~/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/bin/python ~/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/linter.py -m pylint ./main.py
    

    PS: We now have a new pylint extension. Please give it a try and see if it works in this scenario: https://marketplace.visualstudio.com/items?itemName=ms-python.pylint

  2. added
    bugIssue identified by VS Code Team member as probable bug
    info-neededIssue requires more information from poster
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Mar 29, 2022
  3. bmarden commented on Apr 5, 2022

    @bmarden

    Hi Karthik Nadig (@karthiknadig), sorry about the delay on this. I ended up switching to using pyenv and the new extension you mentioned and that is working correctly.

    However I did recreate the environment where it linting wasn't working and ran the command you mentioned and it doesn't look like there is a linter.py at that location

    /Users/bmarden/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/bin/python: can't open file '/Users/bmarden/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/linter.py': [Errno 2] No such file or directory
    

    However I copied the command that vscode is running in the output window and ran that (slightly different path to linter.py):

    ~/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/bin/python ~/.vscode/extensions/ms-python.python-2022.4.0/pythonFiles/linter.py -m pylint ./main.py
    

    And the output:

    Traceback (most recent call last):
      File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/Users/bmarden/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/lib/python3.10/site-packages/pylint/__main__.py", line 9, in <module>
        pylint.run_pylint()
      File "/Users/bmarden/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/lib/python3.10/site-packages/pylint/__init__.py", line 24, in run_pylint
        PylintRun(sys.argv[1:])
      File "/Users/bmarden/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/lib/python3.10/site-packages/pylint/lint/run.py", line 385, in __init__
        score_value = linter.generate_reports()
      File "/Users/bmarden/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1256, in generate_reports
        self.reporter.display_messages(report_nodes.Section())
      File "/Users/bmarden/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/lib/python3.10/site-packages/pylint/reporters/json_reporter.py", line 31, in display_messages
        json_dumpable = [
      File "/Users/bmarden/.local/share/virtualenvs/blog-db-loader-7J7v1WBI/lib/python3.10/site-packages/pylint/reporters/json_reporter.py", line 33, in <listcomp>
        "type": msg.category,
    AttributeError: 'dict' object has no attribute 'category'
    

    Hope this helps. Let me know if I can provide any further info.

  4. karthiknadig commented on Apr 5, 2022

    @karthiknadig
    Member

    Ben Marden (@bmarden) that is older version of the extension, can you update to the latest? Also, that error seems to be in pylint which is this one pylint-dev/pylint#4740. Can you confirm that you are not using pre-release version of pylint.

  5. bmarden commented on Apr 5, 2022

    @bmarden

    You are indeed correct about my pylint version. The one I had installed was the alpha release. For whatever reason pipenv installed that version by default.

    pylint --version output

    pylint 3.0.0-a4
    astroid 2.6.6
    Python 3.10.2 (main, Feb  2 2022, 06:19:27) [Clang 13.0.0 (clang-1300.0.29.3)]
    

    I downgraded to 2.13.4 and it solved the issue. Thanks for the help with this, and sorry about the confusion :)

  6. locked as resolved and limited conversation to collaborators on May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-lintingbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from poster

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions