I've setup a custom configuration file for Pylint (name, conveniently, config). There has to be a way that I don't have to include --rcfile=config
on every run. How can I set the config file permanently?

- 13,247
- 4
- 43
- 57

- 11,819
- 19
- 91
- 145
3 Answers
When you do not specify the --rcfile option, Pylint searches for a configuration file in the following order and uses the first one it finds:
pylintrc
in the current working directory- If the current working directory is in a Python module, Pylint
searches up the hierarchy of Python modules until it finds a
pylintrc
file. This allows you to specify coding standards on a module-by-module basis. Of course, a directory is judged to be a Python module if it contains an__init__.py
file. - The file named by environment variable PYLINTRC
.pylintrc
in your home directory, unless you have no home directory or your home directory is /root.pylintrc
in the current working directory/etc/pylintrc
Thus depending on the method you choose, Pylint can use a different configuration file based on the location of the code, the user or the machine.
Note that the configuration file only applies to Python files that are in modules. Thus, Pylint still uses its default rules when analyzing Python files in a directory with no __init__.py
file.
For example, I have a bin/
directory containing command line applications. Ordinarily, this directory needs no __init__.py
file because it is never imported. I had to add a bin/__init__.py
file to get Pylint to analyze these Python files using my pylintrc
file.

- 9,117
- 9
- 42
- 50
set the path to that file in the PYLINTRC environment variable, or rename the file $HOME/.pylintrc or /etc/pylintrc (the latter is probably only supported on *nix)

- 13,247
- 4
- 43
- 57
-
Where is the environment variable located? I found a folder ~/.pylint.d but it only contains stats on past runs. – Chris Oct 06 '11 at 14:28
-
I don't understand your question. Environment variables are OS level things. What is your operating system ? – gurney alex Oct 10 '11 at 07:53
-
Running OS X Lion. So I would save it at ~/.pylintrc? – Chris Oct 10 '11 at 14:59
-
not a max user myself. Maybe http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x will be helpful. – gurney alex Oct 11 '11 at 12:02
-
But yes, saving the file as ~/.pylintrc should definitely do the trick. – gurney alex Oct 11 '11 at 12:09
-
1according to the man page the sytem wide config should be in /etc/pylintrc – Jens Timmerman Apr 02 '12 at 15:30
It can be done using .pre-commit-config.yaml
. This snippet below need to be added to .pre-commit-config.yaml
:
repos:
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args: [
"-rn", # Only display messages
"-sn", # Don't display the score
"--rcfile=.pylintrc", # Link to your config file
"--load-plugins=pylint.extensions.docparams", # Load an extension
]

- 1,540
- 1
- 6
- 22