Python is one of the most widely used programming languages in the world. With its easy-to-learn syntax, Python is a popular choice for beginners and experienced developers alike. Python is quite a versatile programming language. It can be used to build all kinds of applications, from simple and complex machine learning algorithms.
Debian 10 includes Python version 3.7, which can be installed or updated using the apt
tool.
At the time of writing, Python 3.8 is the latest major release of the Python language. It includes many new features, such as assignment expressions, positional-only arguments, f-string support, and more. Python 3.8 is not available in the standard Debian 10 repository.
This tutorial describes how to install Python 3.8 on Debian 10. We will also show you how to create a virtual environment.
Installing Python 3.8 on Debian 10
Building Python 3.8 on Debian is a relatively simple process that takes only a few minutes.
First install the packages needed to build the Python source code.
|
|
Use there wget or curl
to download the latest version of the source code from the Python page strip. At the time of writing, the latest version is 3.8.2
.
|
|
After the download is complete, extract the zip package.
|
|
Go to the Python source directory and run the configure
script.
The script performs a number of checks to ensure that all dependencies are present on the system. The -enable-optimizations
option will optimize the Python binaries by running multiple tests, which will slow down the build process.
Run -make
to start the build process.
|
|
Modify -j
to correspond to the number of cores in the processor. You can find the number by typing nproc
in the terminal.
Once the build is complete, run the following command as a user with sudo access to install the Python binaries.
|
|
Please do not use the standard make install
as it will overwrite the default system python3
binary.
So far, Python 3.8 is installed and ready to use on your Debian system. You can verify this by entering the following.
|
|
|
|
Creating a Virtual Environment
A Python virtual environment is a separate directory tree that includes the Python binary and many other packages. It allows you to install Python modules in isolated locations for specific projects, rather than globally. This way, you don’t have to worry about affecting other Python projects.
In this example, we will create a new Python 3.8 project named my_app
in the user’s home directory.
First, create the project directory and switch to it.
|
|
Run the following command from inside the project root to create a virtual environment named my_app_venv
.
|
|
Activation environment.
|
|
Once activated, the shell prompt will be prefixed with the environment name. Starting with Python 3.4, the package manager for Python will be installed by default when creating the virtual environment pip.
In a virtual environment, you can use pip
instead of pip3.8
and python
instead of python3.8
.
|
|
|
|
When you are done deactivating the environment, type deactivate
and you will be returned to the regular shell.
|
|
Conclusion
We have shown you how to install Python 3.8 on Debian 10. You can now create a virtual environment and start developing Python 3 projects.