I built and installed python3.8 in raspbian and changed PATH

export PATH=$HOME/.local/bin/:$PATH

I run

>>which python3
>>python3 --version
Python 3.8.0
>>whereis python3
python3: /usr/bin/python3.7m-config /usr/bin/python3.7m /usr/bin/python3.7 /usr/bin/python3.7-config /usr/bin/python3 /usr/lib/python3.7 /usr/lib/python3 /etc/python3.7 /etc/python3 /usr/local/lib/python3.7 /usr/include/python3.7m /usr/include/python3.7 /usr/share/python3 /home/pi/.local/bin/python3.8-config /home/pi/.local/bin/python3.8 /home/pi/.local/bin/python3 /usr/share/man/man1/python3.1.gz

however when I run

>>sudo python3 --version
Python 3.7.3
>>sudo which python3

how can I change sudo python3 to point to 3.8

  • Yep what @steeldriver said; this is a typical sudo usage concern. Nov 14 '19 at 1:51

You can use sudo -E COMMAND in order to preserve the enviroinment of your user. In your case:

sudo -E python3 --version

If the problem is still here, you can use the following command to override the path only for the selected command:

sudo "PATH=$PATH" python3 --version
# OR
sudo env "PATH=$PATH" python3 --version
  • no It is still not working
    – david
    Nov 14 '19 at 18:05
  • this part worked sudo "PATH=$PATH" python3 --version # OR sudo env "PATH=$PATH" python3 --version
    – david
    Nov 14 '19 at 18:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.