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

后端 未结 6 2223
梦毁少年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条回答
  •  借酒劲吻你
    2020-12-01 18:52

    The fix in my case was to remove Defaults !env_reset from sudoers.

    But, I had to keep Defaults env_keep += "PYTHONPATH" in sudoers.
    I've actually added Defaults env_reset (which resets environment variables), but it still works because of env_keep.

    It seems that env_keep and !env_reset conflict with eachother, but that's just a guess.


    So, the whole process:

    1. add export PYTHONPATH=/your/custom/path to ~/.bashrc or /etc/bash.bashrc
    2. add PYTHONPATH to Defaults env_keep += "ENV1 ENV2 ..." in sudoers file
    3. remove Defaults !env_reset from sudoers file if present

提交回复
热议问题