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

后端 未结 6 2218
梦毁少年i
梦毁少年i 2020-12-01 18:04

EDIT: Works for root, sudo is the problem. Read below.

I have a directory with my own libraries, e.g. my Python libraries are located at /home/name/lib/py

6条回答
  •  Happy的楠姐
    2020-12-01 18:47

    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.

提交回复
热议问题