Install python 3.9 on Raspberry PI
Subscribe to my newsletter and never miss my upcoming articles
Installing python 3.9 on a Raspberry Pi in a few easy to follow steps in a few lines of code. This guide will help to get Python installed within minutes.
Update! 30 Sept 2021
I’ve written several Python installation articles about installing Python 3.8, Python 3.9.5 and Python 3.9.7. But if you really want to go the easy way, go to my Ultimate Python installation script!
On the first of October 2020 I have written the blog post “Install Python 3.8 on a Raspberry Pi“. That article about how to install Python 3.8 on a Raspberry Pi got a lot of attention. A lot of people read my article an started using Python 3.8. But now there is Python 3.9 so I thought why not write an article on how to install Python 3.9 on a Rasperry Pi!
Raspberry PI What?
The Raspberry Pi is a low cost, credit-card sized computer that you can plug into a computer monitor, mouse and keyboard. It is a capable little device that enables people of all ages to explore computing, and to learn how to program in languages like Scratch and Python. The Raspberry runs on linus and has it’s own distro called Raspberry PI OS.
The **Raspberry Pi OS** is the Foundation’s official supported operating system and comes pre-installed with 2 versions of Python. Last time I checked 2.7.x and 3.5.x. And as you want to develop in Python 3, you need to specify the version of Python you are using each time and that is annoying! So, lets install the 3.9 version and make it your default!
Install Python 3.9 on a Raspberry PI
First make sure you can ssh to your Raspberry Pi. The default SSH user and password on Raspberry Pi OS are:
– login: pi
– password: raspberry
You cannot login to your Raspberry Pi with SSH? Read this!
First install the dependencies needed to build:
Updating…. this takes a while, grab a coffee and get me one to!!
Next download the latest python version, untar it and compile it.
Building and compiling python can take a while (depends on the Raspberry Pi you have and the amount of memory). And when done, lets install what was build!
Lets do a cleanup and remove the files we don’t need anymore
Make Python 3.9 default on Raspberry Pi
Finally! Let’s make Python 3.9 the default version, make aliases by:
If you still have a 2.x or 3.x version and not the 3.9 version, or when you get an error message do as following.
Go to the last line (arrow down) and find something like:
And change this to
If you cannot find any python related alias in your bashrc file just add the above line to your file.
Do a CTRL+X and CTRL+Y
Then in the terminal do:
This refreshes the bashrc in your terminal
Verify the Python version by:
and hopefully you see:
Your are ready to go!
Happy programming!! Questions? Let me know in the comments below!
Did you find this article valuable?
Support Theo van der Sluijs by becoming a sponsor. Any amount is appreciated!
Как установить Python на Raspberry Pi 3 Model B
$ sudo rm -rf /var/lib/apt/lists
$ sudo apt-get update && sudo apt-get update -y
$ sudo apt-get install -y libssl-dev openssl libreadline-dev build-essential libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev
Текущая версия установленного языка Python:
А я хочу использовать самую последнюю, а значит буду собирать из исходников:
$ tar zxf Python-3.6.2.tgz
/Python-3.6.2 $ ./configure —enable-optimizations
/Python-3.6.2 $ make -j 4
(процедура очень долгая (у меня ушло около 2 часов), советую запастись терпением и на это время переключиться на что-нибудь что повысит Ваши профессиональные навыки)
/Python-3.6.2 $ sudo make install
После проверяю, а какая версия python от третьей версии сейчас в системе с учетом шагов установки выше:
Теперь нужно установить менеджер модулей (а он оказывается уже установлен) которые можно будет устанавливать из консоли для использования в своих программах/скриптах:
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
Пример поиска в репозитариях pip модуля по названию:
$ pip3 search turtle
На этом у меня все, да можно использовать python, но есть ли смысл использовать самую последнюю версию пакета устанавливаемую таким долгим образом или же ограничиться второй версией. Мне кажется да! Если только Вы целенаправленно остановились на ней, как к примеру я. Сижу читаю и практикую, а после адаптирую примеры под Python 3. Так что полезно. До новых заметок на моем блоге, с уважением Олло Александр aka ekzorchik.
Используйте прокси ((заблокировано роскомнадзором, используйте vpn или proxy)) при использовании Telegram клиента:
Поблагодари автора и новые статьи
будут появляться чаще :)
Большое спасибо тем кто благодарит автора за практические заметки небольшими пожертвованиями. С уважением, Олло Александр aka ekzorchik.
Installing Python 3.10 on Raspberry Pi
Subscribe to my newsletter and never miss my upcoming articles
Play this article
Python 3.10.0 is out right now! Installing it on a Raspberry Pi or Ubuntu is very easy with this simple script! You dont need a step by step guide.
‼️ Update: There is now a Ultimate Python installation script. For any version you want to install!
On the 4th of October 2021 Python 3.10.0 was released! Python 3.10.0 is the newest major release of the Python programming language, and it contains many new features and optimizations.
As you might already know Python is a simple, easy to learn program language that emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse.
And now we have Python 3.10.0! Finally! A lot of people have been waiting for this new version.
And I’m guessing you want this new version on your Raspberry Pi.
The Raspberry Pi is a very low cost, small credit-card sized computer that you can use with a computer monitor, keyboard and mouse. It is a little device that enables you to explore computing, and to learn how to program in languages like Scratch and Python! Yes it run Python 3.10.0.
Raspberry Pi runs it own OS called Raspberry Pi OS. The **Raspberry Pi OS** is the Foundation’s official supported operating system and comes pre-installed with a somewhat older version of Python. I’m not sure why but it still contains the 2.7.x Python version and a slightly newer 3.5.x Python version.
I guess you being no this page, you want to install the new 3.10.0 version!
Python 3.10 installation
You can try to update python on a Raspberry Pi by updating the Raspberry Pi OS, but that will not work!
I have been writing a lot about installing Python on a Raspberry Pi, a lot of my articles contain simple to follow steps. I created articles about installing Python 3.8, Python 3.9 and Python 3.9.7. But at a certain point I did not want to create a page with step by step guide to install.
So I created scripts for installing Python versions. But I also did not want to create a script for each python version out there. I know that version 3.11.0 is already being developed and I wanted a one script to rule them all.
So I’ve made it easy! One script one line easy!
One simple Line to install Python 3.10.0 on your Raspberry Pi or on Your Ubuntu System.
So, open a terminal go to your Raspberry Pi with SSH and run the single line on it.
When running my script it’s time to get a cup of coffee, as it takes some time. Oh and don’t forget to ☕ buy a cup of coffee ☕ for me for all my hard work! Thank you!!
Step By Step Python on Raspberry Pi installation
Sorry, I do not have a step by step guide anymore to help you do all the steps by hand.
You can still open my script and read the code and do it by hand. Or take a look at my explanation about the script on this page.
Did you find this article valuable?
Support Theo van der Sluijs by becoming a sponsor. Any amount is appreciated!
How to Install and Use Python Packages on Raspberry Pi?
Python is already installed on Raspberry Pi, but using it to create scripts and build various projects will often require some dependencies named libraries or modules. Even if you are good with Python, you might need some help knowing how to install new packages for Python on Raspberry Pi, which is exactly why I wrote this article.
Most of the Python packages for Raspberry Pi are available in the APT repositories. Searching for the library name with this tool will be the fastest way to install them. Another tool named “PIP” can also be used for some other modules not included in the default repositories.
Either way, I’ll explain everything in this article. I’ll start with APT because most modules can be installed with it, then I’ll introduce PIP and will conclude with a few tips on how to manage your Python libraries.
By the way, if you get overwhelmed as soon as Python is required for a project, I recommend checking out my e-book “Master Python on Raspberry Pi“. It will guide you step-by-step to learn the essential concepts (and only the essential concepts) required to achieve any project in the future. Raspberry Pi without Python is like a car without an engine, you miss all the fun parts. Get 10% off by downloading it today!
Install Python packages on Raspberry Pi
The easiest way to install new Python packages is to use APT (or the graphical version of it: “Add/Remove Software”). The most common Python libraries will be available in the repositories, often named something like “python3-library”.
Find Python packages on Raspberry Pi
A Python package is created to have reusable code at hand in any project. For example, a Python library can help with mathematics functions, interaction with an API, or a specific accessory. By using this kind of module, you don’t need to code the same functions in every new project.
It’s possible to create Python libraries yourself when you work on big projects, but most of the time, you’ll just download and install packages available in the Raspberry Pi OS repositories.
I’ll explain how to do this with the “Add / Remove Software” tool or the “apt” command line directly, but the first thing to know is the package name you need to install.
Recommended Python libraries on Raspberry Pi
The next section works well when you have a specific Python module that you are interested in (and which is available in the repositories), but maybe you are just looking for ideas and don’t know which packages you should install.
First, I recommend starting by reading this article that gives 15 cool Python project ideas on Raspberry Pi. It’s always better to start with a goal in mind and build something from there, rather than trying things without clear objectives.
Then, here are a few interesting Python libraries you can use with the method explained below:
- Sense HAT: It’s the most popular HAT for Raspberry Pi, and there is a great module available for it. You can read my tutorial here if you are interested, I explain everything on how to use this fantastic extension.
- Gui Zero: The example I take in the next section, it’s an easy way to create a basic user interface in Python (forms, buttons, etc.).
- Minecraft Pi: Minecraft was preinstalled on Raspberry Pi on previous Raspberry Pi OS version. It’s a limited but comes with a Python library to interact with the game, which is a great way to get started with Python, especially for kids. Read my tutorial here to get started with Minecraft and Python.
- OpenCV: Looking for something more advanced? OpenCV is a computer vision library that you can use to experiment with machine learning.
Check my tutorial to learn how to setup OpenCV on your Raspberry Pi.
And by the way, if you are entirely new to Python, it’s probably not the first tutorial you should read on this website. I recommend starting here, where I explain the basics of Python. You don’t need any library to create your first script.
Install new Python packages on Raspberry Pi
- On Raspberry Pi OS with Desktop, open the Add / Remove Software tool.
- Type the library name you are looking for in the search engine.
Let’s say “guizero” as an example.
- The tool will show you the corresponding packages:
- Check the corresponding box and click on “Apply” to install it on your system.
- A few seconds later, the package is installed and ready to use in Python.
If you don’t have a desktop environment or prefer to use the command line, here is the equivalent with commands:
- In a terminal, type the following command to find the exact package name:
apt search guizero
- Then install the corresponding package:
sudo apt install python3-guizero
Learn Python, Scratch, & more in an easier way
This all-in-one kit comes with a Raspberry Pi 4-based laptop with tons of sensors and motors under the keyboard.
Are you a bit lost in the Linux command line? Check this article first, for the most important commands to remember, and a free downloadable cheat sheet so you can have the commands at your fingertips.
Using PIP on Raspberry Pi
Even if the most common Python libraries are available in the Raspberry Pi OS repositories, there are many others that can’t be installed this way. Most developers use other methods to share their libraries with the world: PIP.
What is PIP on Raspberry Pi?
PIP is a package manager for Python packages, it’s preinstalled on Raspberry Pi OS and allow installing libraries that are not available in the default repositories.
It’s like a secondary repository, where it’s easier to upload and share a Python library, so most developers use it to maintain their code. For the end-user (you!), it’s also easy to use, as installing PIP packages is not more complicated than using apt.
You can access the web portal of this tool here, and use the search engine to find a Python library you can install on Raspberry Pi. I explain everything in the next sections.
Install PIP on Raspberry Pi
PIP is already installed on Raspberry Pi OS by default. If you are using another operating system or have removed it, here is how to install it:
sudo apt install python3-pip
Same thing as with any Python package, there are two packages available in the repository: python-pip and python3-pip. Make sure to install and use the version corresponding to your Python installation (link to my tutorial where I give more details about this issue).
Install Python packages with PIP on Raspberry Pi
There is a search command available with PIP, but it seems that it isn’t available anymore (“PyPI’s XMLRPC API is currently disabled due to unmanageable load and will be deprecated in the near future”), so the best way to find packages name is to use the website:
- Let’s say you are looking for a Python library to use the Twitter API.
- Go to pypi.org and look for Twitter in the search engine:
- Then browse the results to find the one corresponding to your needs. You can sort the results by relevance, trends, and last update.
Try to avoid libraries that are no longer updated, especially in this case.
- On the library page, you’ll generally get some documentation and the command to use to install the package.
pip install python-twitter
On Raspberry Pi, you need to use sudo, and also to use pip3 if you run your script with Python 3:
sudo pip3 install python-twitter
If there are any required dependencies, pip will install it automatically on your Raspberry Pi. In this example, the packages “future”, “requests” and “requests-oauthlib” will be installed automatically as they are required by python-twitter
Where are Python packages installed?
Once downloaded and installed, Python packages are stored under /usr/lib/python3/dist-packages. Using “pip3 show” will display the exact location for each package: “pip3 show requests” for example.
And I will give you other commands you can use to get a better idea of what is installed on your Raspberry Pi in the next section.
Want to chat with other Raspberry Pi enthusiasts? Join the community, share your current projects and ask for help directly in the forums.
Use Python packages on Raspberry Pi
List of the installed Python libraries on Raspberry Pi
There are several methods to install Python packages and also to list those already installed on a Raspberry Pi. The more complete way is to use help(“modules”) in the console or a graphical equivalent with Thonny.
List Python modules from the console
- Open the Python console with:
- Type the help command to display all available modules:
It may take some time depending on the number of packages installed, and also display some errors and various debug information, but you should receive a complete list at the end.
By the way, if it is unclear to you why Python is used on Raspberry Pi, you should click on that link to know everything about it. It’s an interesting story that any Raspberry Pi enthusiast should know.
Thonny is the default Python text editor on Raspberry Pi OS with Desktop. If you are using this version, there is a hidden feature with the list of Python modules available:
- In the main menu, open Thonny Python IDE from the Programming submenu.
- Click on “Switch to regular mode” if you are in basic mode, and restart it.
- Then there is a menu on top, click on Tools > Manage packages.
- A window like this one will show up:
- You’ll receive the same information as with the previous method, in a more user-friendly way.
List installed packages with PIP
With PIP, there is a command you can use to show all installed packages, here it is:
You’ll get a list with all of the installed packages and the corresponding version. It will be much quicker, but I’m not certain if it really includes everything (those not installed with PIP for example).
List installed Debian packages
And finally, the last way is to check the packages installed with apt, for example:
sudo dpkg -l | grep «python3-«
You can use this command on a fresh installation to see what is already included on your system.
Import a Python library in a script
Once the Python library is installed, with apt, PIP, or any other way, it can be imported into the source code by adding this line at the beginning of the script:
Then follow the corresponding documentation to use all the new functions offered by this module.
For example, my example is a library to create HTTP requests in Python, with a simple code like this:
r = requests.get(‘https://api.github.com/events’)
Much simpler than doing it everything yourself from scratch 🙂
Python libraries are really powerful, so make sure to check if something that can help you already exists before spending hours creating your own functions.
Getting started with Python on Raspberry Pi
By the way, if you need help getting started with Python, you can read by tutorial for Python beginners here, and also check my new e-book, “Master Python programming on Raspberry Pi” in the store. I start from scratch and explain only the important steps, the goal is to practice and achieve the results you want faster.
Python is an essential skill to learn when you want to start new projects on Raspberry Pi, the best ones often require Python code to automate the process. For example, most Raspberry Pi robot kits are programmed in Python.
Raspberry Pi Resources
Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now.
Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Download the e-book.
If you just want to hang out with me and other Raspberry Pi fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.
Need help building something with Python?
Create, understand and improve any Python script for your Raspberry Pi.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.
You can also find all my recommendations for tools and hardware on this page.
I’m the lead author and owner of RaspberryTips.com. My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials. In real life, I’m a Linux system administrator with a web developer experience.
OpenCV is often used to promote Raspberry Pi capacities. Even if the Raspberry Pi is a cheap piece of hardware, showing it with a camera, using artificial intelligence and electronics is pretty.
Sometimes, we start with Ubuntu Server for a minimal project, but after a few weeks, we realize that having a desktop environment would be easier for other things. You don’t need to reinstall.
Hi, I’m Patrick. I am a Linux system administrator, and I am passionate about the Raspberry Pi and all projects on this topic.
I created this site to share with you what I learned about it.
Raspberry Pi Course
Sale: 10% off today.
Get started the right way on Raspberry Pi, follow my tips and save a lot of time by doing your first steps with me.