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:
cd ~
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
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
Compile and Install
tar zxf Python-3.8.0.tgz
cd Python-3.8.0
./configure --enable-optimizations
make -j 4
sudo make altinstall
Validation
Executing this on the command line should work just fine and return the version installed:
pi@vice-pi:~ $ python3.8 -V
Python 3.8.0
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:
alias python='/usr/local/bin/python3.8'
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
References
- https://www.scivision.dev/compile-install-python-beta-raspberry-pi/
- https://installvirtual.com/how-to-install-python-3-8-on-raspberry-pi-raspbian/
- https://www.ramoonus.nl/2019/10/23/how-to-install-python-3-8-on-raspberry-pi/
- https://stackoverflow.com/questions/2812520/dealing-with-multiple-python-versions-and-pip