This short guide explains how to install Python version 3.9.0 on a Raspberry Pi running Raspbian.
First install the dependencies needed to build
sudo apt-get update
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
Compile (takes a while!)
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tar.xz
tar xf Python-3.9.0.tar.xz
cd Python-3.9.0
./configure --prefix=/usr/local/opt/python-3.9.0
make -j 4
Install
sudo make altinstall
And remove the files
cd ..
sudo rm -r Python-3.9.0
rm Python-3.9.0.tar.xz
. ~/.bashrc
Make Python 3.9 the default version, make aliases
sudo update-alternatives --config python
And verify:
python -V
when i try make alias i get error-
update-alternatives: error: no alternatives for python
pls let me know how to fix? now if i do python -V.. i still get “Python 2.7.16” further Python 3.9 is located under /usr/local/opt/python-3.9.0/– why is that so?
@OoMyDaze:
Add this to your ~/.profile:
PATH=”/usr/local/opt/python-3.9.0/bin:$PATH”
logout and back in. Then you can start Python3.9 with python3.9