Running python script in Kicad 6 on macos

Hi,

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/kicad.app/Contents/Frameworks/python/site-packages/")
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/KiCad.app/Contents/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/")

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!

Cheers,
Fabien

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:
/Applications/KiCad/KiCad.app/Contents/Frameworks/Python.framework/Versions/3.8/bin/python3
and it worked…

thank you for your help!

2 Likes