

How To Install Python 3.10 on Debian 11|10
source link: https://computingforgeeks.com/how-to-install-python-on-debian-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Welcome to this guide on how to install Python 3.10 on Debian 11|10. Python 3.10 is the latest release version of Python but not stable as compared to the previous version Python 3.9, the final candidate is yet to be completed soon. Python being one of the widely used open-source object-oriented programming language, gains its popularity due to its simple and easy-to-learn syntax. Python is used in the following areas:
- Handling big data and performing complex mathematics.
- Connecting to database systems, reading and modifying files.
- Rapid prototyping or production-ready software development.
- Used alongside software to create workflows.
- Creating web applications.
The latest release version, Python 3.10 comes with the following cool features;
- Structural Pattern Matching
- Parenthesized Context Managers
- Better Error Messages
- Interpreter improvements with precise numbers for debugging
- More updates on typing features that allow union types as X|Y, parameter specification variables e.t.c
- Security updates e.t.c
Having known the new features for Python 3.10, let’s install it on our Debian 11|10 system.
Getting Started
For this guide, you will need:
- Debian 11|10 Operating system installed
- A user with sudo privileges.
Update your system.
sudo apt update && sudo apt upgrade
Download Python 3.10 on Debian Debian 11|10
In this guide, we will install Python 3.10 on Debian 11|10 by building it from the source code. One advantage of this method is that we are guaranteed the latest available version of Python.
We first need to install the required dependencies to be able to build Python 3.10 from the source.
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
Then download Python 3.10 from the official Python release page. While on this page, download the Python 3.10 Gzippeed tarball. Alternatively, get the download link and pull it with Wget as shown.
wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0rc2.tgz
With the tarball downloaded, extract it as below.
tar -xf Python-3.10.*.tgz
Navigate into the extracted directory and run the configure command to check if the required dependencies are available. In the command, the –enable-optimizations flag is used to optimize the binary and run multiple tests
cd Python-3.10.0rc2
./configure --enable-optimizations
Sample Output:
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.10... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
.........
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup.local
creating Makefile
When the check is complete, build Python 3.10 from the source as below. Remember to speed up the process by using the -j flag. This specifies the number of cores in your system. nproc
command shows your system cores.
make -j 4
Sample Output:
.................
changing mode of build/scripts-3.10/pydoc3 from 644 to 755
changing mode of build/scripts-3.10/idle3 from 644 to 755
changing mode of build/scripts-3.10/2to3 from 644 to 755
renaming build/scripts-3.10/pydoc3 to build/scripts-3.10/pydoc3.10
renaming build/scripts-3.10/idle3 to build/scripts-3.10/idle3.10
renaming build/scripts-3.10/2to3 to build/scripts-3.10/2to3-3.10
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fno-semantic-interposition -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -fprofile-use -fprofile-correction -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Programs/_testembed.o ./Programs/_testembed.cgcc -pthread -fno-semantic-interposition -Xlinker -export-dynamic -o Programs/_testembed Programs/_testembed.o libpython3.10.a -lcrypt -lpthread -ldl -lutil -lm -lm
make[1]: Leaving directory '/home/klinsmann/Python-3.10.0rc2'
When make is complete, proceed and install Python 3.10 on Debian 11|10 as below.
sudo make altinstall
The altinstall
flag is used to maintain the default Python binary path in /usr/bin/python.
Output:
Looking in links: /tmp/tmpjgyu604w
Processing /tmp/tmpjgyu604w/setuptools-57.4.0-py3-none-any.whl
Processing /tmp/tmpjgyu604w/pip-21.2.3-py3-none-any.whl
Installing collected packages: setuptools, pip
WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
distutils: /usr/local/include/python3.10/setuptools
sysconfig: /home/klinsmann/Python-3.10.0rc2/Include/setuptools
WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
distutils: /usr/local/include/python3.10/pip
sysconfig: /home/klinsmann/Python-3.10.0rc2/Include/pip
Successfully installed pip-21.2.3 setuptools-57.4.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Verify your installation.
$ python3.10 --version
Python 3.10.0rc2
Install Python Modules|Extensions on Debian 11|10
Extensions and modules are essential on Python as they add functionality to the Python application. These extensions and modules can be installed on Debian 11|10 using the Python Package Manager(PIP) which is installed using the command:
sudo apt install python3-pip
With PIP, you can easily install a module of choice using the syntax.
sudo pip install module-name
Let’s demonstrate this using a module called beautifulsoup4.
sudo pip install beautifulsoup4
Sample Output:
Collecting beautifulsoup4
Downloading beautifulsoup4-4.10.0-py3-none-any.whl (97 kB)
|████████████████████████████████| 97 kB 259 kB/s
Collecting soupsieve>1.2
Downloading soupsieve-2.2.1-py3-none-any.whl (33 kB)
Installing collected packages: soupsieve, beautifulsoup4
Successfully installed beautifulsoup4-4.10.0 soupsieve-2.2.1
Create a Python Virtual Environment
A Python Virtual environment is where the Python interpreter, libraries, and scripts are installed. To ensure that Python is correctly installed on our Debian 11|10 system, let’s create a simple Python Project.
Create a project directory.
mkdir ~/sample_app && cd ~/sample_app
While in the directory, we will create a virtual environment for the sample_app
python3.10 -m venv sample_app_venv
The next step is to activate the environment.
source sample_app_venv/bin/activate
Sample Output:
root@debian:~/sample_app# source sample_app_venv/bin/activate
(sample_app_venv) root@debian:~/sample_app#
From the output, we are now in the shell, and the name of the app is prefixed. Exit the virtual environment using the command.
deactivate
Conclusion
That marks the end of this guide. We have successfully walked through how to install Python 3.10 on Debian 11|10, install modules and create a virtual environment. I hope this was of significance to you.
See more:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK