Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a python path in sudo state?

My problem is that when I do :

$ which python => I get /a/b/c/python as my directory

but if I do $ sudo which python => I get /d/e/python as the result

How do I change the sudo one to match with the normal case, it is making it impossible to install libraries from source.

like image 535
Kakashi Avatar asked Dec 03 '25 16:12

Kakashi


1 Answers

According to https://askubuntu.com/questions/477987/two-python-distributions-sudo-picking-the-wrong-one this is a result of secure_path (specified in /etc/sudoers) overriding your normal PATH.

I've worked around it by giving the path to the path to the binary I want to run. For example:

$ which pip
/opt/local/bin/pip
$ sudo /opt/local/bin/pip install foo

It's not ideal but it works and doesn't subvert secure_path.

like image 200
Rob Russell Avatar answered Dec 06 '25 09:12

Rob Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!