1

I just got my first Raspberry Pi, and I wanted to use the latest version of Python, but I don't know how to set it up so that when I run python in the command line, it will run Python 3.8.2, rather than 3.7.3. I downloaded the latest release of Python from the website, but it's not a setup script, and I'm not sure how to set it to the path otherwise. Is there a way to replace the default version on Raspbian with the version I've just downloaded?

This is my first time working with any kind of Linux distro, so when I look for the answer on SO or elsewhere, I don't quite know how to word it, and there are very different answers, which makes me think I'm not asking the right question. What could I be doing wrong, and how can I set it up correctly?

Thanks.

OakenDuck
  • 485
  • 1
  • 6
  • 15
  • 1
    `latest source` - you have to compile the source first. Usually all source packages have a file called "README" or similar. Or [some file with build instructions](https://github.com/python/cpython#id4). Read it. – KamilCuk Mar 05 '20 at 03:21
  • 2
    you probably do not want to *remove* the default Python, raspian is a linux distro, so the operating system uses that Python, and you shouldn't touch it. – juanpa.arrivillaga Mar 05 '20 at 03:29
  • 3
    I would also highly suggest to not futz w/ the default python; have you considered [anaconda](https://stackoverflow.com/questions/39371772/how-to-install-anaconda-on-raspberry-pi-3-model-b)? – tink Mar 05 '20 at 05:53
  • 2
    Do you get the Python3.8 when you do `python3`? Then that should be enough. It is **never** a good idea to remove/replace the system default `python`. You can instead install different versions of Python. – Gino Mempin Mar 05 '20 at 08:59
  • 1
    Also, if you are working on Raspberry Pi, you might be interested to know about [Raspberry Pi Stack Exchange](https://raspberrypi.stackexchange.com/help/on-topic). They have similar questions over there, like [this](https://raspberrypi.stackexchange.com/q/98600). – Gino Mempin Mar 05 '20 at 09:00

1 Answers1

2

First Way: You can change Python 3.8.x as the default to Python 3.8.x.

As you said that you have already installed the latest version.Right after that,
Add Python3.8.x & Python 3.8.x to update-alternatives

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8.0 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8.2 2

Update Python 3 to point to Python 3.8.x

sudo update-alternatives --config python3 Enter 2 for Python 3.8.2 or 1 for 3.8.0

python3 --version
Python 3.8.2 

Second Way: Find out what python binary executables are available on your system.

$ ls /usr/bin/python*
/usr/bin/python3.8.0  /usr/bin/python3.8.2 

To Change python version:
Create an alias within user's home directory. Open ~/.bashrc file and add new alias to change your default python executable:

alias python='/usr/bin/python3.8.2'

Once you make the above change, re-login or source your .bashrc file:

$ . ~/.bashrc

Check your default python version:

   $ python --version
    Python 3.8.2
  • I would like to add that the version that was on the os was actually `3.7.3`, rather than `3.8.0`. Also, it tells me that `--install needs `, whereas it originally told me that the path didn't exist. – OakenDuck Mar 05 '20 at 03:46
  • 1
    How about the second solution? try both of them and see if it is working or not! actually the first way is for ubuntu os. I thought maybe it will work. However, I am sure that the second way will fix it. – ABDULAZIZ NOREDIN QADMOR Mar 05 '20 at 03:55