Updating a Raspberry Pi to Python 3.9
I'm starting a project that will involve creating an API in Python, and for that purpose I want to use FastAPI. However, FastAPI requires Python 3.6 or newer, and my Raspberry Pi could only install 3.5 from the package manager. Because of this, I have to install and build Python 3.9.7 manually on my system.
I wanted to install Python 3.10.0, which is the latest, but because it requires OpenSSL 1.1.1 I decided to stick with 3.9. I didn't want to spend the extra time updating other packages.
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev
wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz
tar xf Python-3.9.7.tar.xz
cd Python-3.9.7
./configure --enable-optimizations
make
sudo make altinstall
After I was finished running those commands, I could either symlink Python 3.9 to /usr/bin/python
or create an
alias in my .bashrc file. I opted for the alias. I also aliased Pip 3.9, which was installed along with Python.
vim ~/.bashrc
alias python='python3.9'
alias pip='pip3.9'
Then, exit vim and source the .bashrc file.
source ~/.bashrc
Now, when I type python --version
into my terminal window, I should now see Python 3.9.7
.