Last Updated on May 21, 2021.
In my Commodore 64 Diorama series, I used Python to read shared memory segments that we wrote to from VICE. However, the version of Python at the time of that Raspbian install was less than the version I needed – 3.8 or higher. Here’s how I installed an alternative version of Python, along with making it the default version and using PIP in a version-specific manner.
Downloading and Updating
The obligatory apt update/apt upgrade, along with installing dependencies:
sudo apt update
sudo apt upgrade
sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev tar wget vim
Compile and Install
tar zxf Python-3.8.0.tgz
make -j 4
sudo make altinstall
Executing this on the command line should work just fine and return the version installed:
pi@vice-pi:~ $ python3.8 -V
Making our install the default version
I prefer to do this by adding the alias to a (potentially new) file .bash_aliases in your home directory by adding this line to the file:
Example PIP updating
Based on some current reading it looks like it’s a good practice to use the python version specific pip for the version you’re running instead of assuming any default. Here’s the example I used to update the python package manager and installing the RPi.GPIO library.
sudo python3.8 -m pip install --upgrade pip
sudo python3.8 -m pip install RPi.GPIO