Fixing KiCAD Custom Plugin Error

macOS

As of this writing, when one attempts to run a custom Python3 plugin script for KiCad (v6) where the script file is not located at /Applications/KiCad/KiCad.app/Contents/SharedSupport/plugins python complains that it cannot find the KiCad libraries.

Apple security boffins have made it all but impossible to set global env variables, so export PYTHONPATH="..." isn’t really an option, when running plugin scripts from within the KiCad GUI (Generate BOM for example.)

I did get that working by wrapping the text in Command line running the generator: with sh -c 'export PYTHONPATH="/Applications/KiCad/KiCad.app/Contents/SharedSupport/plugins && [original command here] ' … but then I realized a …

Better Way (probably)

In your custom Python script, change this …

import kicad_netlist_reader
import kicad_utils
import csv
import sys

… to this …

import sys
sys.path.append("/Applications/KiCad/KiCad.app/Contents/SharedSupport/plugins")
import kicad_netlist_reader
import kicad_utils
import csv

About

Born suspiciously male on a small blue planet during its one thousand nine hundred and seventy first orbit chasing an unremarkable star in a galaxy tucked away at the edge of the universe where nothing of much interest happens and even less is remembered.

Leave a Reply

Your email address will not be published. Required fields are marked *

*