fix: Resolve Python executable validation failure on Linux (Issue #29)

This commit fixes the critical bug where the MCP server fails to start on
Linux with "Python executable not found: python3" even when python3 is
correctly installed and available in PATH.

Root Cause:
- findPythonExecutable() returned 'python3' (command name) on Linux
- validatePrerequisites() used existsSync('python3') which checks current
  directory, not PATH
- Validation failed even though spawn() would resolve 'python3' via PATH

Changes Made:

1. Enhanced findPythonExecutable() for Linux (src/server.ts:42-126):
   - Added Linux platform detection
   - Check KiCad bundled Python paths first (/usr/lib/kicad/bin/python3, etc.)
   - Use 'which python3' to resolve system python3 to absolute path
   - Fallback to common system paths (/usr/bin/python3, /bin/python3)
   - Import execSync for 'which' command execution

2. Improved validatePrerequisites() (src/server.ts:214-266):
   - Distinguish between absolute paths and command names
   - Use existsSync for absolute paths
   - Use --version execution test for command names
   - Added Linux-specific error messages and troubleshooting

3. Documentation Updates (README.md:409-444):
   - Added "Linux Python Detection" section
   - Documented detection priority order
   - Added troubleshooting steps for KICAD_PYTHON
   - Clarified that no manual config needed for standard installations

Testing:
- Build completed successfully (npm run build)
- Python detection now resolves /usr/bin/python3 on Ubuntu/Debian
- Maintains backward compatibility with Windows/macOS
- KICAD_PYTHON override still works

Fixes #29

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
KiCAD MCP Bot
2026-01-10 22:23:54 -05:00
parent aa18486359
commit d2723bc292
2 changed files with 121 additions and 10 deletions

View File

@@ -406,6 +406,43 @@ Edit configuration file:
- **Windows:** `C:\Program Files\KiCad\9.0\lib\python3\dist-packages`
- **macOS:** `/Applications/KiCad/KiCad.app/Contents/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages`
#### Linux Python Detection
The server automatically detects Python on Linux in this priority order:
1. **Virtual environment** - `venv/bin/python` or `.venv/bin/python` (highest priority)
2. **KICAD_PYTHON env var** - User override for non-standard installations
3. **KiCad bundled Python** - `/usr/lib/kicad/bin/python3`, `/usr/local/lib/kicad/bin/python3`, `/opt/kicad/bin/python3`
4. **System Python via which** - Resolves `which python3` to absolute path (e.g., `/usr/bin/python3`)
5. **Common system paths** - `/usr/bin/python3`, `/bin/python3`
**For most standard Linux installations (Ubuntu, Debian, Fedora, Arch), no KICAD_PYTHON configuration is needed** - the server will automatically find your Python installation.
**Troubleshooting:**
If you see "Python executable not found: python3", you can manually specify the Python path:
```json
{
"mcpServers": {
"kicad": {
"command": "node",
"args": ["/path/to/KiCAD-MCP-Server/dist/index.js"],
"env": {
"KICAD_PYTHON": "/usr/bin/python3",
"PYTHONPATH": "/usr/lib/kicad/lib/python3/dist-packages"
}
}
}
}
```
To find your Python path:
```bash
which python3 # Example output: /usr/bin/python3
python3 -c "import pcbnew; print(pcbnew.GetBuildVersion())" # Verify pcbnew access
```
### Cline (VSCode)
Edit: `~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json`