Problem
I've been trying to run a python script which imports from the Foundation package:
from Foundation import ...
Whenever I try to run this I get the following error:

Things I've done:
I've installed the Foundation package and verified that it was installed in /usr/local/lib/python3.7/site-packages
I've added export PYTHONPATH='/usr/local/lib/python3.7/site-packages' to my .zshrc file.
When I go into interactive mode, sys.path includes /usr/local/lib/python3.7/site-packages and I can successfully import Foundation:
When I run the script using /usr/local/bin/python3.7, sys.path does not include /usr/local/lib/python3.7/site-packages and importing Foundation fails:
Does anyone know why this might be happening and/or how to fix this? Why does running this script have a different sys.path than running the same python executable in interactive mode?
(I know I could use sys.path.extend(desired path) or something like that but that's not an ideal solution)


First, you run Python as your user (say
~joeor whatever your UID is) but then you bringsudoto the table. And that's where things starts to differ, because it will not inherit your environment. Simple test for you to replay (substitutepython3by whatever path/version you want):then the same but with
sudo:To work this around you either need to ensure your superuser's environment fits your needs or you feed python interpreter with needed value of
PYTHONPATHon the fly: