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 …

Better Way (probably)

In your custom Python script, simply 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

I guess KiCad itself may be able to fix this quirk on macOS some day. For now, I’ll stick with what’s working.

Author: gruvin

Born anatomically male, of a largely uninteresting bipedal, carbon based species, during the ninth moon orbit of the one thousand, nine hundred and seventy first meaningfully recorded solar orbital cycle (according to Gregory) of a small blue planet, situated near the outer edge of a seemingly long forgotten galaxy, located at the precise centre of its universe. In short; — I am. Therefore, I am.

Leave a Reply

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