Welcome to this definitive tutorial on setting up Python on AlmaLinux 9. Python 3.12 is the most recent major advancement of the Python programming language, offering an array of innovative features, enhancements, and library improvements.
Installing Python on AlmaLinux 9
1. Updating the System
Before delving into installation, it is pivotal to ensure your system is updated for preventing potential conflicts and guaranteeing smooth installation. To update system packages, initiate your terminal and input:
sudo dnf clean all sudo dnf update
Post system update, we need to install critical development tools and libraries, which are crucial for building and installing Python from the source. Execute the following to install required packages:
sudo dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel
2. Installing Python 3.12.1
Begin by downloading the latest Python 3.12 source code tarball from the official website:
wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz
Verify the integrity of the downloaded file using SHA-256 checksum or GPG signature. Afterwards, extract the compressed tarball:
tar xzf Python-3.12.1.tgz
This creates a Python-3.12.1
directory. Proceed into it:
cd Python-3.12.1
Prior to compiling the source code, run the configuration script which checks the system for dependencies and prepares the build environment. To run the configuration script with optimizations:
./configure --enable-optimizations
Next, compile the source code using make
command. The -j
option allows specifying the number of cores to utilize, accelerating the build process:
make-j4
Upon completion of the build process, install Python 3.12 using make altinstall
command:
sudo make altinstall
Finally, verify that Python 3.12 was installed correctly by checking the Python version:
python3.12 --version
3. Upgrading Pip & Installing Modules
Some Python modules may not yet be available for Python 3.12. Therefore, upgrade pip
initially:
python3.12 -m pip install --upgrade pip
4. Setting Up Python Virtual Environment
Working within a virtual environment is a best practice in Python development. It isolates Python projects and their dependencies, preventing conflicts. To create a virtual environment for Python 3.12.1 installation, utilize the venv
module:
/usr/local/bin/python3.12.1 -m venv myenv
This command creates a new virtual environment named myenv
. To activate it:
source myenv/bin/activate
With the virtual environment active, you can now install and manage Python packages isolated from the system Python.
For businesses seeking efficient, scalable, and secure cloud hosting solutions, check out Shape.host’s Linux SSD VPS services. They offer professional and reliable services, empowering businesses with top-notch cloud hosting solutions.