Package: pylint-venv
pylint-venvPylintdoes not respect the currently activatedvirtualenvif it is not
installed in every virtual environment individually.  This module provides
a Pylint init-hook to use the same Pylint installation with different virtual
environments.Installationpipinstallpylint-venvAdd the hook to your Pylint configuration. See the section below corresponding
to the type of configuration file you use.Configure withpyproject.tomlAdd the following to yourpyproject.toml:[tool.pylint.MAIN]init-hook="""
try: import pylint_venv
except ImportError: pass
else: pylint_venv.inithook()
"""Configure with.pylintrcAdd the following to your.pylintrc:[MAIN]init-hook=try:import pylint_venvexcept ImportError:passelse:pylint_venv.inithook()If you add this to your~/.pylintrcin your home directory, it will be
applied to all projects by default.UsageThe hook will then be used automatically ifa virtualenv without pylint is active,or a Conda environment without pylint is active,or no environment is active but your CWD contains virtualenv directory.Anything listed in thePYLINT_VENV_PATHenvironment variable is considered
a virtualenv directory. The default, if the variable is unset, is.venv. Use
a colon (:) as path separator. Example for checking directories.venvand.virtualenv:PYLINT_VENV_PATH=.venv:.virtualenvYou can also call the hook via a command line argument:$pylint--init-hook="import pylint_venv; pylint_venv.inithook()"This way you can also explicitly set an environment to be used:$pylint--init-hook="import pylint_venv; pylint_venv.inithook('$(pwd)/env')"Ifpylintitself is installed in a virtualenv, then you can ignore it by passingforce_venv_activation=Trueto force the activation of a different virtualenv:$pylint--init-hook="import pylint_venv; pylint_venv.inithook(force_venv_activation=True)"This will try to automatically detect virtualenv and activate it.TroubleshootingGeneralpylint_venv fails to importMost likely pylint-venv is not installed in the same virtual environment as
pylint. Either make sure to ensure pylint-venv into the same virtual environment
as pylint, or add the appropriate path in the init hook:importsyssys.path.append("/path/to/installation/folder/of/pylint_venv")pylint_venv breaks parsing with toolsWhen tools call pylint with-f json, an extra line may break the parser, as the
output is no longer valid json. To avoid printing “using venv …”, passquiet=Truetoinithook$pylint-fjson--init-hook="import pylint_venv; pylint_venv.inithook(quiet=True)"Virtual environment does not get used (installed modules are reported as ‘unable to import’)Most likely the virtual environment does not get activated because pylint itself
runs in a virtual environment. You can force the activation of the virtual
environment with theforce_venv_activation=Trueflag to thepylint_venv.inithookfunction.HomebrewHomebrew installs pylint into a separate virtual environment, thus you will
need to set theforce_venv_activation=Trueflag. This also means, that
pylint_venv will be in a different search path and you must add the proper
path tosys.path. You can use the following configuration adjusted to your
Python version:[MAIN]init-hook=import syssys.path.append("/usr/local/lib/python3.8/site-packages")try:import pylint_venvexcept ImportError:passelse:pylint_venv.inithook(force_venv_activation=True)