I am trying to run a Pipenv python instance as root. When not run as root:
(myenv) $ python script.py
the Pipenv python is correctly used. However, when run as root with sudo:
(myenv) $ sudo python script.py
the system default python at /usr/bin/python is used instead. After some searching, I found the -E option for sudo. However, with
(myenv) $ sudo -E python script.py
it still uses /usr/bin/python, even though sudo -E echo $PATH gives the same as echo $PATH, so the -E option works fine; however, sudo -E which python continues to give /usr/bin/python! It is not a permissions or access problem because the full path to the Pipenv python works fine. Why is the wrong binary being used even though $PATH is set correctly?