Home        Store        Learn        Blog

Updating Python in Companion

Is Python 3.7 and up supported on this companion version?

Hi @farhang,

Companion 0.0.28 still uses Raspbian Jessie, so the default Python 3 install is 3.4. That doesn’t stop you from installing a later version separately if you want to, but be aware it’s a few steps and takes a while for it to compile. I’ve provided instructions below if you’re interested in doing so.

As a timing indication, expect the full process to take ~30-60 minutes.

Requires Internet Connection

Check that your companion computer is connected to the internet. On the companion web interface Network page your “Internet Status” should say connected.

Connect to the Raspberry Pi

You can either use the terminal over browser functionality, or you can ssh in (default password is companion).

Stop Companion Functionality

Compiling code wants all the CPU it can get - close the non-essential screen sessions to allow compiling to have more resources. Keep the web-related sessions open to allow webterminal use, and monitoring CPU usage and temperature with companion web interface.

for SESSION in $(screen -ls | grep "(" | cut -f2 | grep -v web)
    screen -S $SESSION -X quit

Update Raspbian

sudo apt-get update

Install Prerequisites

Installing Python on Linux is much smoother if some dependencies are installed first

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

Download and Extract Python

# specify which version you want to install
# download it
wget https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tgz
# uncompress it
sudo tar zxf Python-${VERSION}.tgz

Make and Install

# enter the source folder
cd Python-${VERSION}
# configure for building (checks for prerequisites, takes a little while) 
sudo ./configure --enable-optimizations
# build the source - expected to be the longest step
# !WARNING! if RPi is enclosed use -j2 or no -j flag to avoid overheating/throttling
sudo make -j4
# install as an 'alternative' (doesn't overwrite existing python3)
# If you want to overwrite it you can do `sudo make install` instead,
#   but that may cause issues with existing libraries not being carried 
#   over - I haven't tried it
sudo make altinstall

Confirm working

The new python install should be available by the major version number. You can check that it’s working by running python3.x -V and seeing if the top line is what you tried to install (e.g. for python 3.8.11 you can run python3.8 -V).

Note there may be a bunch of messages like profiling:...: Cannot open - these are related to the source and will be removed in the next step.

Clean up

# exit the Python source directory
cd ..
# remove the compressed and extracted Python source
sudo rm -rf Python-${VERSION}*


  • From here you can run code using your new Python version by calling it with the major version number (e.g. python3.8 my_script.py).
  • If you prefer executing scripts directly you can set the shebang to #! /usr/local/bin/python3.8 (or whichever version you’re using)
  • For installing libraries pip is also accessible via the major version number (e.g. pip3.8 install ...), or you can use python3.8 -m pip install ....

The normal companion functionality will be available again after restarting the raspberry pi.

1 Like

Thanks alot @EliotBR . Currently we are using a branch which was given to me from Bluerobotics.
I will try this soon which no idea whan it would be.

This took a bit of time. I tried it on the latest companion and apt update is giving the below output:

Hit http://archive.raspberrypi.org jessie InRelease
Ign http://mirrordirector.raspbian.org jessie InRelease
Ign http://mirrordirector.raspbian.org jessie Release.gpg                               
Ign http://mirrordirector.raspbian.org jessie Release          
Hit http://archive.raspberrypi.org jessie/main armhf Packages
Hit http://archive.raspberrypi.org jessie/ui armhf Packages                          
Ign http://archive.raspberrypi.org jessie/main Translation-en_GB                                    
Ign http://archive.raspberrypi.org jessie/main Translation-en                         
Ign http://archive.raspberrypi.org jessie/ui Translation-en_GB
Ign http://archive.raspberrypi.org jessie/ui Translation-en
Err http://mirrordirector.raspbian.org jessie/main armhf Packages                                                                                                                                                 
  404  Not Found [IP: 80]
Err http://mirrordirector.raspbian.org jessie/contrib armhf Packages                                                                                                                                              
  404  Not Found [IP: 80]
Err http://mirrordirector.raspbian.org jessie/non-free armhf Packages                                                                                                                                             
  404  Not Found [IP: 80]
Err http://mirrordirector.raspbian.org jessie/rpi armhf Packages                                                                                                                                                  
  404  Not Found [IP: 80]
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en_GB                                                                                                                                           
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en                                                                                                                                              
Ign http://mirrordirector.raspbian.org jessie/main Translation-en_GB                                                                                                                                              
Ign http://mirrordirector.raspbian.org jessie/main Translation-en                                                                                                                                                 
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en_GB                                                                                                                                          
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en                                                                                                                                             
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en_GB                                                                                                                                               
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en                                                                                                                                                  
W: Failed to fetch http://mirrordirector.raspbian.org/raspbian/dists/jessie/main/binary-armhf/Packages  404  Not Found [IP: 80]                                                                     

W: Failed to fetch http://mirrordirector.raspbian.org/raspbian/dists/jessie/contrib/binary-armhf/Packages  404  Not Found [IP: 80]

W: Failed to fetch http://mirrordirector.raspbian.org/raspbian/dists/jessie/non-free/binary-armhf/Packages  404  Not Found [IP: 80]

W: Failed to fetch http://mirrordirector.raspbian.org/raspbian/dists/jessie/rpi/binary-armhf/Packages  404  Not Found [IP: 80]

E: Some index files failed to download. They have been ignored, or old ones used instead

Do you have any input on it?

I fixed it in sources list. Ok now. Will try your solutuon after.