Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again.
| Rule( |
| 9 | id="python.module_not_found", |
| 10 | tool="python", |
| 11 | title="Python module not found", |
| 12 | why="Python could not import a module — it is not installed in the active environment, " |
| 13 | "or the import path is wrong.", |
| 14 | checks=( |
| 15 | "Is the package installed in this virtualenv?", |
| 16 | "Is the import name different from the PyPI name?", |
| 17 | "Are you using the intended Python interpreter?", |
| 18 | ), |
| 19 | fixes=( |
| 20 | "pip install <package>", |
| 21 | "python -c \"import sys; print(sys.executable)\"", |
| 22 | ), |
| 23 | patterns=( |
| 24 | Pattern("ModuleNotFoundError", kind="exact", required=True), |
| 25 | ), |
| 26 | confidence="high", |
| 27 | secondary=("No module named",), |
| 28 | ), |
| 29 | Rule( |
| 30 | id="python.import_error", |
| 31 | tool="python", |
| 32 | title="Python ImportError", |
| 33 | why="An import failed — the module exists but a symbol is missing, or a dependency failed to load.", |
| 34 | checks=( |
| 35 | "Is the imported name spelled correctly?", |
| 36 | "Did a native extension fail to load?", |
| 37 | "Is the package version incompatible?", |
| 38 | ), |
| 39 | fixes=( |
| 40 | "Check the traceback for the underlying cause", |
| 41 | "Reinstall the package: pip install --force-reinstall <package>", |
| 42 | ), |
| 43 | patterns=( |
| 44 | Pattern("ImportError:", kind="exact", required=True), |
| 45 | ), |
| 46 | confidence="medium", |
| 47 | secondary=("cannot import name",), |
| 48 | ), |
| 49 | Rule( |
| 50 | id="python.no_matching_distribution", |
| 51 | tool="python", |
| 52 | title="No matching distribution found", |
| 53 | why="pip could not find a package version compatible with your platform or Python version.", |
| 54 | checks=( |
| 55 | "Is the package name correct?", |
| 56 | "Does it support your Python version?", |
| 57 | "Are you on an unusual platform/architecture?", |
| 58 | ), |
| 59 | fixes=( |
| 60 | "pip index versions <package>", |
| 61 | "Upgrade pip: python -m pip install -U pip", |
| 62 | "Use a supported Python version", |
| 63 | ), |
| 64 | patterns=( |
| 65 | Pattern("No matching distribution found", kind="exact", required=True), |
| 66 | ), |
| 67 | confidence="high", |
| 68 | secondary=("pip", "ERROR:"), |
| 69 | ), |
| 70 | Rule( |
| 71 | id="python.externally_managed", |
| 72 | tool="python", |
| 73 | title="Externally managed Python environment", |
| 74 | why="This Python is managed by the OS (PEP 668); pip refuses to install into it globally.", |
| 75 | checks=( |
| 76 | "Are you trying to pip install system-wide?", |
| 77 | "Do you have a virtual environment?", |
| 78 | ), |
| 79 | fixes=( |
| 80 | "python -m venv .venv && source .venv/bin/activate # Windows: .venv\\Scripts\\activate", |
| 81 | "Then: pip install <packages>", |
| 82 | ), |
| 83 | patterns=( |
| 84 | Pattern("externally-managed-environment", kind="exact", required=True), |
| 85 | ), |
| 86 | confidence="high", |
| 87 | secondary=("PEP 668", "pip"), |
| 88 | ), |
| 89 | Rule( |
| 90 | id="python.permission_denied", |
| 91 | tool="python", |
| 92 | title="Python / pip permission denied", |
| 93 | why="The interpreter or pip could not write to a path due to permissions.", |
| 94 | checks=( |
| 95 | "Are you installing into a system path?", |
| 96 | "Should you use a virtualenv instead of sudo?", |
| 97 | ), |
| 98 | fixes=( |
| 99 | "Use a virtual environment instead of sudo pip", |
| 100 | "Fix ownership of the target directory", |
| 101 | ), |
| 102 | patterns=( |
| 103 | Pattern("Permission denied", kind="exact", required=True), |
| 104 | Pattern( |
| 105 | r"pip|site-packages|python", |
| 106 | kind="regex", |
| 107 | required=True, |
| 108 | ), |
| 109 | ), |
| 110 | confidence="medium", |
| 111 | ), |
| 112 | Rule( |
| 113 | id="python.syntax_error", |
| 114 | tool="python", |
| 115 | title="Python SyntaxError", |
| 116 | why="The Python parser rejected the source — invalid syntax at the reported location.", |
| 117 | checks=( |
| 118 | "Which file and line are reported?", |
| 119 | "Are you running code with a Python version that lacks that syntax?", |
| 120 | ), |
| 121 | fixes=( |
| 122 | "Open the file:line from the traceback and fix the syntax", |
| 123 | "Ensure the correct Python version is used", |
| 124 | ), |
| 125 | patterns=( |
| 126 | Pattern("SyntaxError:", kind="exact", required=True), |
| 127 | Pattern( |
| 128 | r"invalid syntax|unexpected EOF|unmatched|Maybe you forgot a comma", |
| 129 | kind="regex", |
| 130 | ), |
| 131 | ), |
| 132 | confidence="high", |
| 133 | secondary=("File ", "line "), |
| 134 | ), |
| 135 | Rule( |
| 136 | id="python.indentation_error", |
| 137 | tool="python", |
| 138 | title="Python IndentationError", |
| 139 | why="Python requires consistent indentation; mixed tabs/spaces or wrong indent caused a failure.", |
| 140 | checks=( |
| 141 | "Are tabs and spaces mixed?", |
| 142 | "Is a block missing or over-indented?", |
| 143 | ), |
| 144 | fixes=( |
| 145 | "Convert indentation to spaces (PEP 8: 4 spaces)", |
| 146 | "Fix the line reported in the traceback", |
| 147 | ), |
| 148 | patterns=( |
| 149 | Pattern( |
| 150 | r"IndentationError:|TabError:", |
| 151 | kind="regex", |
| 152 | required=True, |
| 153 | ), |
| 154 | ), |
| 155 | confidence="high", |
| 156 | ), |
| 157 | Rule( |
| 158 | id="python.pip_dependency_conflict", |
| 159 | tool="python", |
| 160 | title="pip dependency conflict", |
| 161 | why="Installed packages have incompatible version requirements.", |
| 162 | checks=( |
| 163 | "Which packages conflict according to the pip report?", |
| 164 | "Can you pin compatible versions?", |
| 165 | ), |
| 166 | fixes=( |
| 167 | "Resolve the conflicting version pins in requirements", |
| 168 | "pip install <pkg>==<compatible-version>", |
| 169 | ), |
| 170 | patterns=( |
| 171 | Pattern( |
| 172 | r"ResolutionImpossible|dependency conflict|conflicting dependencies|" |
| 173 | r"Cannot install .+ because these package versions have conflicting dependencies", |
| 174 | kind="regex", |
| 175 | required=True, |
| 176 | ), |
| 177 | ), |
| 178 | confidence="high", |
| 179 | secondary=("pip",), |
| 180 | ), |
| 181 | Rule( |
| 182 | id="python.version_incompatible", |
| 183 | tool="python", |
| 184 | title="Python version incompatibility", |
| 185 | why="The package or code requires a different Python version than the one in use.", |
| 186 | checks=( |
| 187 | "What Python version are you running?", |
| 188 | "What version does the package require?", |
| 189 | ), |
| 190 | fixes=( |
| 191 | "python --version", |
| 192 | "Install/use a compatible Python with pyenv, uv, or your OS packages", |
| 193 | ), |
| 194 | patterns=( |
| 195 | Pattern( |
| 196 | r"Requires-Python|requires a different Python|requires Python|" |
| 197 | r"python_requires|not compatible with your Python|unsupported Python", |
| 198 | kind="regex", |
| 199 | required=True, |
| 200 | ), |
| 201 | ), |
| 202 | confidence="high", |
| 203 | secondary=("pip",), |
| 204 | ), |
| 205 | Rule( |
| 206 | id="python.type_error", |
| 207 | tool="python", |
| 208 | title="Python TypeError", |
| 209 | why="An operation received a value of the wrong type at runtime.", |
| 210 | checks=( |
| 211 | "Which argument or operand has the wrong type?", |
| 212 | "Is None being passed where an object is expected?", |
| 213 | ), |
| 214 | fixes=( |
| 215 | "Inspect the traceback arguments and fix the types", |
| 216 | "Add validation or defaults for None/unexpected inputs", |
| 217 | ), |
| 218 | patterns=( |
| 219 | Pattern("TypeError:", kind="exact", required=True), |
| 220 | ), |
| 221 | confidence="low", |
| 222 | ), |
| 223 | Rule( |
| 224 | id="python.attribute_error", |
| 225 | tool="python", |
| 226 | title="Python AttributeError", |
| 227 | why="Code accessed an attribute or method that does not exist on the object.", |
| 228 | checks=( |
| 229 | "Is the object the type you expect?", |
| 230 | "Was the attribute renamed in a new library version?", |
| 231 | ), |
| 232 | fixes=( |
| 233 | "Check the object type and API docs for the correct attribute", |
| 234 | "Print/repr the object just before the failing line", |
| 235 | ), |
| 236 | patterns=( |
| 237 | Pattern("AttributeError:", kind="exact", required=True), |
| 238 | ), |
| 239 | confidence="medium", |
| 240 | ), |
| 241 | ] |