I'm writing this to ask what is the difference between executing python as normal user and previleged (i.e, sudo) user.
I have a python script that installs python package in specific directory (here, /usr/local is used), and in order to do that the script should be run with sudo.
The script seems calling external binary, however in sudo mode it fails to find it using find_executable(~), whereas it succeeds flawlessly without sudo command.
Here's code: calling script with & without sudo, respectively. Both codes have (nearly but impactless) identical contents.
Note that both python is identical, as I called it explicitly in sudo mode (I found that without specifying python binary path executes system-wide python).
w/ sudo:
sudo /home/.../anaconda3/envs/pytorch_open3d/bin/python
Python 3.8.8 (default, Feb 24 2021, 21:46:12)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.spawn import find_executable
>>> pyside2Uic = ["pyside2-uic", "python2-pyside2-uic", "pyside2-uic-2.7"]
>>> found_pyside2Uic = any([find_executable(p) for p in pyside2Uic])
>>> print(found_pyside2Uic)
False
w/o sudo:
which python
/home/.../anaconda3/envs/pytorch_open3d/bin/python
python
Python 3.8.8 (default, Feb 24 2021, 21:46:12)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.spawn import find_executable
>>> pyside2Uic = ["pyside2-uic"]
>>> found_pyside2Uic = any([find_executable(p) for p in pyside2Uic])
>>> print(found_pyside2Uic)
True
I also tried answer already provided (link), which is an argument that preserves current environment information, but has no effect:
sudo -E /home/.../anaconda3/envs/pytorch_open3d/bin/python
Python 3.8.8 (default, Feb 24 2021, 21:46:12)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.spawn import find_executable
>>> pyside2Uic = ["pyside2-uic"]
>>> found_pyside2Uic = any([find_executable(p) for p in pyside2Uic])
>>> print(found_pyside2Uic)
False
Is there anything I missed? Any helps are greatly appreciated. Thanks in advance.
ps. result of echo
echo $PATH
/home/.../anaconda3/envs/pytorch_open3d/bin:/home/.../anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
sudo echo $PATH
[sudo] password for ...:
/home/.../anaconda3/envs/pytorch_open3d/bin:/home/.../anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin