X
X

Select Your Currency

Türk Lirası $ US Dollar
X
X

Select Your Currency

Türk Lirası $ US Dollar

Knowledge Base

Installing Python on Debian

 

Python Installation on Debian

 

Python is one of the most widely used programming languages in modern software development. Installing Python on a Debian-based system should be done carefully to maintain system stability and compatibility. This document outlines the step-by-step process for installing Python on Debian.

 

Updating System Packages

 

Before beginning the installation, it is recommended to update the existing system packages. This helps improve stability and prevents potential package conflicts.

sudo apt update
sudo apt upgrade -y

 

Checking the Installed Python Version

 

Debian systems usually come with a default version of Python. To check the currently installed version:

python3 --version

 

Installing Python 3

 

If Python is not installed or if the current version is outdated, Python 3 can be installed using the following command:

sudo apt install python3 -y

 

Installing pip

 

On some systems, the pip package manager may not be available by default. pip is essential for managing Python packages and can be installed with:

sudo apt install python3-pip -y

After installation, the pip version can be verified with:

pip3 --version

 

Installing Development Tools (Optional)

 

Some Python libraries require compilation. Installing development tools ensures these packages can be built and used properly:

sudo apt install build-essential libssl-dev libffi-dev python3-dev -y

 

Installing an Alternative Python Version from Source

 

If the latest Python version is not available in the Debian repositories, it can be installed manually from the official source. The steps below demonstrate how to install Python 3.12:

 

sudo apt install wget make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev -y
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz
sudo tar xzf Python-3.12.3.tgz
cd Python-3.12.3
sudo ./configure --enable-optimizations
sudo make -j "$(nproc)"
sudo make altinstall

 

Note: The make altinstall command installs the new version without replacing the default python3 binary. The new version will be available as "python3.12".

 

Managing Default python and pip Commands

 

To link the python and pip commands to specific versions, use the following:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1

 

Using Virtual Environments

 

To isolate dependencies for each project, virtual environments can be created using the venv module:

python3 -m venv project-env
source project-env/bin/activate

By following the steps above, a reliable and up-to-date Python development environment can be established on a Debian system. This setup enables secure and manageable development for Python-based applications.

Did you find it useful?
(4 times viewed / 0 people found it helpful)

Can't find the information you are looking for?

Create a Support Ticket
Top