Upgrade default Python 3.5.3 to Python 3.7.2 on Raspberry Pi 3 Stretch
Solution 1
Great that you are having fun with your PI! I hope I can help you, please leave a comment if you have more questions.
In Linux, an alias
is a setting in your shell, the program that you talk with to control your PI. But as soon as you leave your PI, the shell program is closed and the alias
setting is thrown away.
To make the change permanent, you can either add the alias
setting to the startup file of your shell (the file .profile
in your home directory), or better, change the links.
To change .profile
, type the following exactly (better to use copy-paste):
echo "alias python3=/usr/local/bin/python3.7" >> ~/.profile
The file .profile
is read during login, so to activate the change you must log out and log in again.
In Unix, a link is a file that points to another file. /usr/bin/python
normally points to /usr/bin/python2.7
, and /usr/bin/python3
points to /usr/bin/python3.5.3
. You can see links by adding the -l
(l
for long) option to ls
, for example ls -l /usr/bin/python*
. Links have permissions set to lrwxrwxrwx
.
I would leave the /usr/bin/python
link alone, this is used by the operating system and that expects certain libraries to be installed that are probably not installed in your new python.
If your new python is /usr/local/opt/python-3.7.2/bin/python3.7
, you can change the python3
link by typing the following commands:
sudo rm /usr/bin/python3
sudo ln -s /usr/local/bin/python3.7 /usr/bin/python3
Solution 2
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
tar xzvf Python-3.7.2.tgz
cd Python-3.7.2/
./configure
make -j4
sudo make install
After that simply do:
echo "alias python3=’/usr/local/opt/python-3.7.2/bin/python3.7′" >> ~/.profile
Hope this work
Related videos on Youtube
Anant Narayan
Studying in 6th standard. Interested in programming in Python.Hobbies include building projects using Raspberry Pi and Arduino. Learning TensorFlow and ROS. Currently building a robotic arm controlled using ROS and TensorFlow Object Detection API.
Updated on June 04, 2022Comments
-
Anant Narayan almost 2 years
I want to upgrade the default Python3 which is Python 3.5.3 to Python 3.7.2. When googled I found many sites telling how to install latest python 3.5 and other versions including python 3.7.0 but none of these sites were telling how to upgrade from python 3.5.3 to python 3.7.2. So I tried to install Python 3.7.2 instead of upgrading the default Python 3.5.3. After some searches I got a guide on How to install Python 3.7 on Raspberry Pi. Here is the link to the website: https://www.ramoonus.nl/2018/06/30/installing-python-3-7-on-raspberry-pi/ . So I followed the steps and successfully installed Python 3.7.0 on my Raspberry Pi 3 and set the alias of python and python3 to python3.7.0 and now when I enter
python --version
orpython3 --version
it gives me 3.7.0. But now I have another problem that is when I shutdown or reboot my Pi and switches it back on and I typepython --version
it gives me 2.7.13 andpython3
it gives me 3.5.3. So please help me with this matter.-
gavin about 5 yearsdoes python3.7 still exist on your system after a reboot, under
/usr/local/opt/
as per the ref link? -
Anant Narayan about 5 yearsYes the folder is still there after reboot.
-
gavin about 5 yearsjust adding an alias would work at this step, similar to what @Deep has mentioned in his answer
-
-
Anant Narayan about 5 yearsI tried to install python 3.7.2 with Deep's instructions and copy-pasted the line in the .profile, logged out and logged in again and when I type python3, it gives me the following error : -bash: /usr/bin/python3: No such file or directory . I would like to know if there is a setup wizard for installing Python 3.7.2 on Linux just like the setup wizard for installing Python on Windows. Thanks.
-
snakecharmerb about 5 yearsDo
make altinstall
, otherwise you will overwrite the system Python, which you almost never want to do. docs.python.org/3/using/unix.html#building-python -
EvertW about 5 yearsWizards? Nah, this situation is not covered by wizards. Wizards only help with situations they foresaw. You are almost done, only the alias in the .profile points to the wrong file. My bad, probably. I'll install P3.7.2 on my own Pi, see where the python3.7 file lives.
-
EvertW about 5 yearsAnant, by following the instructions of Deep I got a Python that lives in /usr/local/bin/python3.7, I edited my instructions accordingly. You can test whether this is the same for you by simply running
/usr/local/bin/python3.7
. If that gets you into python3.7.2, you're OK to just repeat the instructions. The extra line in .profile does not matter. You might want to open the file in e.g.gedit
and remove it for extra thoroughness points ;-) -
Anant Narayan about 5 yearsThank you Evert, I followed instructions given by you and now my default Python 3 is Python 3.7.2 . Thanks Everyone.Special thanks to Evert:-)
-
EvertW about 5 yearsMy Pleasure, Anant! I hope you will get just as hooked to programming as me 40 years ago ;-) It is a great way to make a living!
-
Anant Narayan about 5 yearsHi Evert. My goal is to make an object detection system using Pi. Could you please tell me how I can proceed.Thank you.
-
EvertW about 5 yearsHave a look at youtube. There are several demos using tensorflow, which is an artificial intelligence framework. If you don't want to use a camera, you could also attach an ultra-sonic rangefinder, e.g. youtube.com/watch?v=sXJjfEisjpo.
-
Anant Narayan about 5 yearsActually I had installed Tensorflow and OpenCV for object detection but OpenCV was not showing the image when I give the imshow() function. My default Python 3 was Python 3.5.3. So I tried to install Python 3.7.2 and got struck, that's when I posted my doubt.Now I reinstalled everything from scratch including Raspbian and now my pi can detect any object.Thank you very much for your valuable help.
-
Sergey over 4 yearsMay I delete directory 'Python-3.7.2' (created by unpacking archive) after install?
-
Timo over 3 yearsShould I make altinstall if I get this:
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020
-
Timo over 3 years@snakecharmerb I just posted a comment. Maybe I can answer my comment: Yes, keep it because if it will reach eol, everything on my system will soon reach eol. So either keep all or get a new system.
-
snakecharmerb over 3 years@Timo if you want to upgrade the system Python, upgrade the system (assuming a Unix-like OS). There will be system packages that depend on the the version of the system Python, so upgrading it by itself will most likely make your system unusable.
-
Rafal over 2 yearsI needed also to install the libffi-dev due to error during make install: sudo apt-get install libffi-dev