In this tutorial, I will show you how to install Python 3.7 on Raspberry Pi running raspbian on it.
Update the Raspbian
Update the Raspbian before installing python.
sudo apt-get update
Read Also: How to install python 3.7 on Ubuntu 16.04 / 18.04
Prerequisites
Before installing python 3.7 there are some dependencies that we need to install. Use the following command to install the required dependencies.
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
1. Download Python
You can download Python from the official website or use the following command.
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
Read Also: How to install postgresql 11 on Debian 8 / 9
2. Install Python 3.7 On Raspberry Pi
Now we will extract and install Python from the source.
sudo tar zxf Python-3.7.0.tgz
cd Python-3.7.0
sudo ./configure
sudo make -j 4
sudo make altinstall
4. Make Python 3.7 as the default version
If you want to use python 3.7 as a default version you can create an alias.
Let’s check the path of Python.
vim ~/.bashrc
alias python='/usr/local/bin/python3.7'
Then source the .bashrc file.
source ~/.bashrc
If the path of Python is not /usr/local/bin/python3.7 the use which to get the path of python.
which python3.7
and then follow the Step 4 again.
/usr/local/bin/python3.7
5. Check Python Version
After creating an alias check the python version again.
python -V
Python 3.7.0
Now you have successfully installed Python 3.7 on Raspberry Pi.
aliases should be written in .bash_aliases
Yes, you can write it in .bash_aliases. But there is no hard rule for that.
There is a typo above: alias python=’/usr/lcoal/bin/python3.7′
It should read: alias python=’/usr/local/bin/python3.7′
Hey Richard,
Thanks for the correction.
Very helpful
Thank you for your feedback.
“vim ~/.bashrc” returns: bash: vim: command not found
Hey Abdul,
You can either install vim
apt install vim -y
or you can use vi
vi ~/.bashrc
quit telling people to use vim or vi. Those are too complicated for beginners. Nano or leafpad ?
Hey Joie,
Thanks for your message. I like to use vim so I write to use the vim. You can feel free to use any other editor of your choice.
When we do the above steps, every time the system turn on it will go into python environment instead of system environment. May I know if there is anywhere to undo the above, ie remove the modification in ./bashrc?
so that at bootup, it will becomes at the prompt of
pi@raspberrypi: etc
appreciate you advice in this as I ma new to raspberry
This is due to the fact that you added to .bashrc file the following lines:
which python3.7
/usr/local/bin/python3.7
If you remove that you will not have that behaviour.
hang on! I’m stuck in python, How do I get a normal terminal back so I can do this?
“This is due to the fact that you added to .bashrc file the following lines:
which python3.7
/usr/local/bin/python3.7”
As I’m stuck in python!
Hey John,
I have updated my post in order to make it easier to follow. Please let me know if can install Python.
Cheers
I know nothing about vim, but does it support the mouse. How does Emacs compare to vim?
Thanks for your useful tutorial.
Thank you so much. Your comments really motivate me for posting new tutorials and articles.