If you‘re looking for a straightforward, step-by-step guide to installing the latest Python 3.9 on Linux Mint 20, you‘ve come to the right place! By following this walkthrough, you‘ll have Python 3.9 up and running on your system in no time.
Here‘s what we‘ll cover:
- What new features and improvements come with Python 3.9
- Preparing your system by updating packages
- Installing Python 3.9 using the deadsnakes PPA repository
- Building and installing Python 3.9 completely from source code
- Tips for managing multiple Python versions
- How to create virtual environments and install packages for Python 3.9
Plus plenty of examples, screenshots, and troubleshooting tips to make the process smooth and simple.
So let‘s get started!
An Overview of Exciting New Features in Python 3.9
Before jumping into the installation, it helps to understand what new goodies Python 3.9 has in store. Let‘s quickly highlight some of the key new features and improvements:
The new dictionary merge operator (|) merges two dicts into one. This provides a concise way to combine dicts without mutating the originals:
dict1 = {‘a‘: 1, ‘b‘: 2}
dict2 = {‘c‘: 3, ‘d‘: 4}
combined = dict1 | dict2 # {‘a‘: 1, ‘b‘: 2, ‘c‘: 3, ‘d‘: 4}
The parser was completely rewritten to be more efficient and extensible. The new parser is up to 2x faster for certain workloads. This improves performance for many Python applications.
Multiline string literals can now use triple quotes """ for defining strings spanning multiple lines, without needing newline escapes.
Type hints have several improvements like TypedDict, @overload, Final, and expanded functools. These features support stronger type checking.
The new vectorcall protocol allows classes to define how their methods receive arguments from the caller. This allows optimization opportunities.
The math module has great new functions like math.prod(), math.isqrt(), math.lcm(), math.ulp(), and more.
Reading and writing data is faster due to changes in the buffer protocol and I/O internals. Performance is up to 2x faster.
Python 3.9 has many more new features and optimizations that make it worthwhile upgrading to the latest version. Now let‘s look at how to install it on Linux Mint 20.
Prerequisites Before Installing Python 3.9
I recommend ensuring your base system is fully up to date before installing Python 3.9. This prevents potential conflicts and ensures you have all required dependencies.
To update your Linux Mint 20 system, open a terminal and run:
sudo apt update
sudo apt upgrade -y
The apt update fetches the latest package metadata.
The apt upgrade actually installs available updates.
I also recommend having at least 3 GB of free disk space before compiling or building Python from source code. The full build process can take over 1 GB temporarily.
With those best practices out of the way, you‘re ready to install Python 3.9!
Method 1: Installing Python 3.9 using the Deadsnakes PPA
The recommended way to install Python 3.9 on Linux Mint 20 is using the Deadsnakes PPA repository.
Deadsnakes is a trusted PPA maintained by a Python core developer that provides packages for newer Python versions.
Here are the detailed steps to install Python 3.9 using the Deadsnakes PPA:
-
Start by updating the package index on your system:
sudo apt updateRunning
apt updateensures you fetch the latest package metadata from all configured repositories. This makes sure you pull Python 3.9 specifically from the Deadsnakes PPA once enabled. -
Install the
software-properties-commonpackage:sudo apt install software-properties-commonThis contains the
add-apt-repositorycommand used to enable new repositories. -
Next, add the Deadsnakes PPA to your apt sources list:
sudo add-apt-repository ppa:deadsnakes/ppaYou‘ll need to hit Enter to confirm adding this new repo.
The Deadsnakes PPA contains multiple Python versions including 3.9 that you can now install.
-
Update apt again to pick up packages from the newly added PPA:
sudo apt update -
Finally, install Python 3.9!
sudo apt install python3.9This will fetch the latest Python 3.9 version specifically from the Deadsnakes repository.
By default, Python 3.9 will install to
/usr/bin/python3.9on your Mint system.
That‘s it! With just these 5 steps you now have Python 3.9 installed from the official Deadsnakes PPA repository.
You can verify Python 3.9 is successfully installed by checking the version:
python3.9 --version
This should print Python 3.9.x where x is the latest patch version.
One thing to note is that Python 3.9 won‘t override or replace the default python3 binary that points to your existing system Python 3.x version. Both will be available side-by-side.
If you ever need to uninstall Python 3.9, run:
sudo apt remove python3.9
Next let‘s go over the process of building and installing Python 3.9 completely from source code.
Method 2: Installing Python 3.9 from Source Code
Building Python from the latest source code is an alternative installation method for those who need complete control over the compile process.
Here are the steps to build and install Python 3.9 from source on Linux Mint 20:
-
Install all required build dependencies with:
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wgetThis command grabs everything needed for compiling Python, including:
build-essential– The GCC compiler toolchain and makezlib1g-dev– Compression librarieslibncurses5-dev– Terminal and screen control via curseslibgdbm-dev– Python DBM database supportlibnss3-dev– Cryptographic and SSL/TLS librarieslibreadline-dev– Advanced line editing and historylibffi-dev– Foreign function interface supportwget– Used for downloading the source code
Having these development packages installed prevents "missing dependency" errors during Python‘s ./configure step.
-
Download the latest Python 3.9 source tarball with wget:
wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgzThis grabs the source code directly from the official python.org servers.
As of this writing, Python 3.9.1 is the latest maintenance release in the 3.9 series.
I recommend putting the downloaded
.tgzfile in your home or Downloads directory for easy access. -
Extract the compressed source tarball:
tar -xf Python-3.9.1.tgzThis unpacks the raw source code into a new
Python-3.9.1directory ready for building. -
Change into the extracted Python source directory:
cd Python-3.9.1 -
Run the configure script with extra optimization flags:
./configure --enable-optimizationsThis runs a series of tests to prepare Python for your system and ensure dependencies are available.
Passing
--enable-optimizationstunes the build for your specific CPU architecture. This results in better performance. -
Now compile Python 3.9 with make:
make -j 8The
-jflag runs a parallel build using 8 CPU cores. This dramatically speeds up compile time.Omit the
-joption to just use 1 core instead if you prefer. Compiling still takes awhile.When the build finishes, you‘ll have the compiled Python 3.9 binaries ready for installation.
-
The last step is to install the freshly built Python 3.9:
sudo make altinstallaltinstallinstalls Python into/usr/local/bininstead of the default location.This prevents the new Python 3.9 from overwriting the system python3 binary. Both can coexist.
Once altinstall completes, Python 3.9 and all its libraries are successfully installed from source!
Double check it is available by running:
/usr/local/bin/python3.9 --version
This should show Python 3.9.x.
Building from source takes longer but ultimately provides the most flexibility and customization if needed.
Now let‘s discuss some tips for managing and working with multiple Python versions installed.
Tips for Managing Multiple Python Versions
It‘s very common to have multiple major Python versions installed, like the latest Python 3.9 alongside the system Python 3.7.
Here are some best practices for managing multiple Python installations:
-
Call versions directly by binary name – Use
python3.9andpython3.7to run specific major versions. -
Set shebang lines – Make scripts executable by adding
#!/usr/bin/env python3.9as the first line. -
Use virtual environments –
python3.9 -m venv myenvcreates isolated virtual environments. -
Change the global
pythonbinary – Switch between versions usingupdate-alternatives. -
Install version-specific packages – Use
python3.9 -m pip installto avoid conflicts.
Let‘s expand on each of these tips:
Call Python binaries directly
Once you have multiple versions installed, you can launch a specific one by calling its binary directly:
python3.9 myscript.py
python3.7 myscript.py
This bypasses any global python symlinks and gives you precise control.
Set shebang lines
For Python scripts you want to make executable, add a shebang line pointing to the version you want:
#!/usr/bin/env python3.9
print("Running under Python 3.9!")
The env lookup finds the python3.9 binary location.
This tells your system exactly which Python version to use when launching that script.
Use virtual environments
Python "virtual environments" allow creating isolated spaces with their own set of installed packages.
You can make a virtual environment for Python 3.9 like:
python3.9 -m venv my_project
This keeps my_project‘s package dependencies separate from others.
Virtualenvs are a best practice for Python project dependency and version management.
Change the global python binary
Sometimes you need to change the symlink of python that runs by default across the whole system.
The update-alternatives command manages these global symlinks:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
Now the python command will point to Python 3.9 rather than 3.7.
Be very careful modifying these global links since it can break dependencies expecting specific versions.
Install version-specific packages
You can install pip packages for a specific Python version like:
python3.9 -m pip install pandas
This adds pandas only to the Python 3.9 install rather than the system Python.
Version-specific package installs prevent accidentally upgrading packages for other Python versions.
So in summary:
- Directly call python3.9 or python3.7 binaries
- Shebang lines control which Python runs scripts
- Virtual environments isolate package dependencies
update-alternativeschanges the system-widepythonsymlink- Install packages per version with
python3.9 -m pip install
These tips help safely manage multiple Python major releases on the same Linux system.
Up next, let‘s go over some examples for creating virtual environments and installing packages for your new Python 3.9 installation.
Creating Virtual Environments and Managing Packages
Python "virtual environments" allow creating isolated execution environments with their own independent set of installed packages.
This allows Python projects to have installation requirements that don‘t interfere with other projects or your system Python packages.
Let‘s look at some examples of managing virtual environments and packages for Python 3.9.
First, create a virtual environment named myproject:
python3.9 -m venv myproject
This will create a new directory myproject containing an isolated Python 3.9 setup.
Next, you need to activate the virtualenv. From inside that project directory, enter:
source bin/activate
Your shell prompt will now show (myproject) indicating you‘re operating inside the virtual environment.
Now install packages just for this environment:
python -m pip install requests flask django
These get added to the myproject virtualenv rather than globally.
You can also install packages via a requirements.txt file:
python -m pip install -r requirements.txt
This is useful for defining the exact dependencies a project needs.
Finally, you can deactivate the virtual environment by running:
deactivate
This restores your original shell session outside the virtual environment.
Some key takeaways around virtual environments:
- Use
python3.9 -m venvto create new virtualenvs source bin/activateenters the virtualenv shellpython -m pip installadds packages to just that environmentdeactivateexits the virtualenv back to normal shell
Following this virtualenv workflow prevents Python package dependency issues between projects and versions.
So in summary, we looked at:
- Creating virtualenvs for Python 3.9
- Activating and deactivating virtualenv shells
- Installing packages within virtualenvs
- Keeping dependencies isolated across Python projects
Learning to use Python 3.9 virtual environments will make dependency and version management much easier as you work on complex Python projects.
Conclusion
Hopefully this guide provided you with a very detailed, step-by-step walkthrough on installing Python 3.9 from either the Deadsnakes PPA repository or building from source code on Linux Mint 20.
We covered:
- An overview of new features in Python 3.9
- Preparing your system with package updates
- Adding the Deadsnakes PPA and installing Python 3.9 packages
- Downloading, compiling, and installing Python 3.9 from source
- Tips for managing multiple Python versions
- Creating virtual environments for Python 3.9 projects
With Python 3.9 now installed, you‘re ready to take advantage of all the latest features and improvements in your Python development!
The use of virtual environments is highly recommended to prevent dependency and version conflicts between Python projects.
I hope you found this guide helpful! Let me know if you have any other questions on getting up and running with Python 3.9.
Happy programming!



