Running python script in Kicad 6 on macos


I am trying to generate a board configuration for openpnp from my kicad design using this script to no avail.

1 - I first tried to run it from my terminal, using the system’s python version.It didn’t work since the script needs to import pcbnew. So, my first question is, is it possible to add kicad python modules to my computer path, and how? Or, how can I import kicad modules from the system console?

2 - I tried running it in kipython from the scripting console using 2 python method to call external scripts (exec(open().read()) and os.system() ) I didn’t get any errors but also no result. that leads me to my second question: What is the proper way to call a python script from the scripting console?

I have to mention that I have found information on how to add the kicad path to an existing script using
import sys
sys.path.insert( 0, "/Applications/Kicad/")
but that path isn’t valid for kicad 6, and when I tried to replace with the path that I thought was equivalent:

sys.path.insert( 0, "/Applications/KiCad/")

it found the pcbnew module but couldn’t find _pcbnew.o

Anyway, if anyone had any info about any of this, that would be greatly appreciated.
Thanks for the help!


I don’t have a mac to verify this but I remember that there is a python binary somewhere there. Try launching the script in console but with that binary instead of system python.

Yes,the python binary that kicad uses is in there, I tried it and it didn’t run. I get an error “cannot execute binary file” I’m guessing a permission issue.

What about chmod +x on the binary?

It wasn’t it… and I figured it out. I was trying to run the wrong binary.
I tried:
and it worked…

thank you for your help!