I am also running in to exactly the same problem as I am trying to call some python code (which processes a .kicad_pcb file) from a bash script.
The python script runs without error from the console but I want to launch it from a bash script (which, apart from this python problem) otherwise runs normally.
I have tried (partially successfully) as suggested by @wezfurlong to address this by adjusting my PYTHONPATH to
and then the following works (but not unless I additionally do the sys.path.insert)
~ $ /Applications/Kicad/kicad.app/Contents/Applications/pcbnew.app/Contents/MacOS/Python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[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.
But this doesn’t seem to work when called from a bash script - I have adjusted the shebang line in my script
(!#/Applications/Kicad/kicad.app/Contents/Applications/pcbnew.app/Contents/MacOS/Python) and included the sys.path.insert.
All being run as unprivileged user - and all relevant scripts have had a
chmod a+x on them.
Running out of ideas now - not really a python expert (or a python anything, to be honest!)
Is this anything to do with System Integrity Protection? https://support.apple.com/en-us/HT204899