I want to make sudo python find Python 3.
I had a strange issue where, in terminal, typing python --version gave 3.6 but sudo python --version gave 2.7. After trying a few things I finally uninstalled 2.7 with sudo apt-get purge python2*. That removed everything correctly. Still, I can't get sudo python to find Python 3.
I've tried changing my /root/.bashrc to have:
export PATH="/home/username/anaconda3/bin:$PATH"
and
alias python="/home/username/anaconda3/bin/python"
and I put the same lines in ~/.bashrc too.
My etc/sudoers has this line:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"/usr/bin:$
I've opened new terminals and even restarted the computer. Any ideas how to make sudo python just find Python 3? I don't want a single session fix but something that will work each time I use the terminal.
Thanks
sudodoesn't respect aliases. It can't, because an alias is a shell operation, butsudois not part of the shell (can't access internal shell state), and directly calls the operating system'sexecve()call to invoke software being called.sudo env PATH="$PATH" pythonshould do the trick.sudo python, but if you're doing that all the time... err... that's a smell. (Not quite a "code smell", necessarily, but let's call it a "bad-practice smell").psudo() { sudo env PATH="$PATH" "$@"; }in your.bashrcand callpsudoinstead ofsudo, and there you are.