pylint doesn't point to virtualenv python

家住魔仙堡 提交于 2019-12-04 22:29:04

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.

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.

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
Jérôme

Noufal Ibrahim's answer works if you execute pylint manually.

If you execute pylint from you editor/IDE, you need to configure the plugin correctly.

It can get tricky. This may be considered a bug of each IDE/plugin, but that's how it is.

Modifying /usr/bin/pylint to write #!/usr/bin/env python as suggested in another answer fixes this for every use of pylint (manual use, or any editor integration).

However, at least in Debian, using #!/usr/bin/python is a design choice, not a bug. The link I provide does not explain the rationale. The maintainer of the pylint package does not want to move to #!/usr/bin/env python.

To avoid modifying that system file, one can create a copy of /usr/bin/pylint in /usr/local/bin:

cp /usr/bin/pylint /usr/local/bin/pylint
vi usr/local/bin/pylint # Edit the file to use /usr/bin/env python

This won't be broken by a pylint update, but still infringes Debian's "strongly preferred choice".

This method requires root privileges. An unprivileged user may create an alias

alias pylint='/usr/bin/env python $(which pylint)'.

There are probably good reasons for #!/usr/bin/python being the preferred form, although I don't understand them.

For now, I'm willing to compromise with this. Using the non-preferred form (creating /usr/local/bin/pylint or using an alias) allows me to avoid pulling my hair figuring out how to configure my linter correctly (assuming it is even feasible).

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.

I know it's been a while since this question was answered, but I just thought I should leave this post here in case someone else runs into the same problem.

If for some reason you need to keep pylint in the global space instead of your virtual environment, you can use the recommendation in here: PyLint + VirtualEnv.

It basically says to configure your pylint using the init-hook and encoding version of a Python program that will use the global pylint and load the rest of the environment.

You can get there by calling the target python interpreter:

./env/bin/python -m pylint ...

# or in an already active env
python -m pylint ...

I'm using the Syntastic + Pylint combination, and since I have many different virtualenvs that I can work on at any given time, I've created a wrapper over the virtualenv command that, among some other things, installs pylint after all the requirements.

That way, whenever I activate a virtualenv, I'll get its own pylint version.

Hope this helps, and thanks for the tip on deleting the global one from @briford-wylie

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!