如何在Pylint的msg-template中配置可点击的文件URL路径?
I’ve run into this exact issue before—Windows’ backslash paths don’t play nice with the file:/// URI scheme that PyCharm recognizes for clickable links. The fix is straightforward: we just need to convert those backslashes to forward slashes directly in Pylint’s message template, using Python’s string replacement capabilities that the template system supports.
Here’s how to set it up:
Option 1: Command Line (One-Time Use)
When running Pylint in PyCharm’s terminal (either CMD or PowerShell), use this modified --msg-template parameter:
pylint --msg-template='(file:///{abspath.replace("\\\\", "/")}:{line}) :{column}: {msg_id}: {msg} ({symbol})' your_target_file_or_dir.py
The \\\\ is necessary because command shells treat backslashes as escape characters—we need two to represent a single literal backslash, and another two for the Python format string’s own escape. This replaces every backslash in the file path with a forward slash, turning a path like C:\Projects\app.py into C:/Projects/app.py—which works perfectly with the file:/// scheme.
Option 2: Pylint Configuration File (Permanent Fix)
For a long-term solution, add this line to your pylintrc file (create one if you don’t have it with pylint --generate-rcfile):
msg-template=(file:///{abspath.replace("\\", "/")}:{line}) :{column}: {msg_id}: {msg} ({symbol})
Here we only use two backslashes because we’re not dealing with command shell escaping—this directly tells Python to replace each backslash in the absolute path with a forward slash.
How It Works
Once configured, Pylint will output links like file:///C:/Projects/app.py:42—PyCharm’s terminal automatically recognizes this as a valid local file URI, and clicking it will jump straight to line 42 of app.py. Even paths with spaces will work correctly, no extra encoding needed.
内容的提问来源于stack exchange,提问作者Stefan

