PYTHONPATH not working for sudo on GNU/Linux (works for root)

The same is true for the PATH variable, it’s also not carried into the super user environment, even though you’re passing the preserve environment flag -E.

I’m using this sudo command now without any other modifications:

sudo -HE env PATH=$PATH PYTHONPATH=$PYTHONPATH ./bin/myscript

Since it’s an alternative approach that works (for me) I thought I’d share here.

Leave a Comment