The issue is that the binaries in the macos bundle are relative to
@executable_path. This is the right thing to use when scripts are run from inside the kicad application, but when you try to load the modules from your own python script, the shared modules that the
pcbnew python depends on are then resolved relative to the apple-provided python binary... and they're not there.
The true fix for this is some adjustment of the build parameters for the application.
If you just want to try things out, then here's a simple local hack: Copy the python executable so that its
@executable_path matches that of KiCad
cp /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python /Applications/Kicad/kicad.app/Contents/Applications/pcbnew.app/Contents/MacOS
Now instead of running
/usr/bin/python to launch your script, you'd use
But before you can
import pcbnew, you need to set the python path so that it knows where to find the kicad modules:
$ PYTHONPATH=/Applications/Kicad/kicad.app/Contents/Frameworks/python/site-packages /Applications/Kicad/kicad.app/Contents/Applications/pcbnew.app/Contents/MacOS/Python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcbnew