pylint doesn't point to virtualenv python

后端 未结 10 1723
执笔经年
执笔经年 2021-01-07 19:19

I am pretty new to python and currenty I am trying to use pylint for checking code quality. I am getting a problem. My pylint doesn\'t point to virtualenv python interpreter

相关标签:
10条回答
  • 2021-01-07 19:29

    Ran into the same problem just today. Continuing on ThorSummoner's answer, when using Pylint with pylint-django inside of a virtual environment such as Pipenv, make sure to call pylint using the target python interpreter (python -m pylint)

    A good approach, which will work locally and on your CI as well is to write-down the lint command in the script section of your Pipfile:

    [scripts]
    lint = "python -m pylint [--options] all-my-modules-names..."
    

    Then calling pylint is as easy as :

    pipenv run lint
    
    0 讨论(0)
  • 2021-01-07 19:32

    I am fairly sure that you need to install pylint under your virtual environment and then run that instance of it.

    Update - Make life easier:

    I would suggest that anybody working a lot in virtual environments create a batch file, (in a known location or on the path), or bash script with something like the following called something like getlint.bat:

    pip install pylint
    

    Invoking this after activating the virtual environment will install pylint into that virtual environment. If you are likely to be offline or have a poor internet connection you can, once when you have a good internet connection, (possibly once for each of python 2 & 3):

    mkdir C:\Some\Directory\You\Will\Leave\Alone
    pip download --dest=C:\Some\Directory\You\Will\Leave\Alone pylint
    

    Which will download pylint and its dependencies to C:\Some\Directory\You\Will\Leave\Alone and you can modify getlint.bat to read:

    pip install pylint --find-links=C:\Some\Directory\You\Will\Leave\Alone
    

    It will then use the pre-downloaded versions.

    0 讨论(0)
  • 2021-01-07 19:33

    When you're using Pipenv / virtualenv, install pylint inside the virtualenv:

    pipenv install --dev pylint
    

    or, if you don't use Pipenv, install it with pip after you activated your virtualenv:

    # activate virtualenv, e.g. `. env/bin/activate`
    pip install pylint
    
    0 讨论(0)
  • 2021-01-07 19:34

    I ran into this problem, too. My solution was simply to edit the pylint program's shebang, like so... (your path to pylint may be different than mine, though)

    $ sudo vim /usr/bin/pylint
    

    Replacing:

    #!/usr/bin/python
    

    With:

    #!/usr/bin/env python
    
    0 讨论(0)
  • 2021-01-07 19:37

    A cheap trick is to run (the global) pylint using the virtualenv python. You can do this using python $(which pylint) instead of just pylint. On zsh, you can also do python =pylint.

    0 讨论(0)
  • 2021-01-07 19:41

    The issue has been solved on chat (link in comments).

    The problem lied in using sudo yum install pylint, because it installed pylint in the global env. The solution was to use the following command:

    pip install -i http://f.pypi.python.org/simple pylint

    Note the -i usage as the regular index seemed to be broken for the asker.

    0 讨论(0)
提交回复
热议问题