{"id":9448,"date":"2024-06-20T09:47:16","date_gmt":"2024-06-20T09:47:16","guid":{"rendered":"https:\/\/www.ssdnodes.com\/?p=9448"},"modified":"2025-05-15T15:44:53","modified_gmt":"2025-05-15T15:44:53","slug":"python-on-almalinux","status":"publish","type":"post","link":"https:\/\/www.ssdnodes.com\/blog\/python-on-almalinux\/","title":{"rendered":"How to Set Up a Programming Environment for Python on AlmaLinux 9"},"content":{"rendered":"<p>Installing Python on AlmaLinux 9 is a simple process. This article will guide you through the installation process, and you\u2019ll also set up a Python virtual environment as a bonus!<\/p>\n<p>Python is a versatile programming language you can use to create web applications, desktop applications, scripts, and many other types of programs. It is also a popular language for scientific computing, data analysis, artificial intelligence, and more. Basically, you can do almost anything with it.<\/p>\n<p>AlmaLinux is a production-grade enterprise operating system that is binary-compatible with Red Hat Enterprise Linux. It was initially released on March 2021 by CloudLinux to provide a community-supported spiritual successor to CentOS Linux.<\/p>\n<p>In this tutorial, you'll set up a programming environment for Python 3 on your AlmaLinux server.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9455\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/AlmaLinux-Python.webp\" alt=\"Python on AlmaLinux\" width=\"768\" height=\"512\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/AlmaLinux-Python.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/AlmaLinux-Python-300x200.webp 300w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/p>\n<h2>Installing Python on AlmaLinux 9 - Prerequisites<\/h2>\n<p>Before you install Python on AlmaLinux, you need:<\/p>\n<ul>\n<li>Basic knowledge of the Linux command line.<\/li>\n<li>An AlmaLinux 9 server with a non-root user with <code>sudo<\/code> privileges. You can get affordable, and powerful AlmaLinux servers from <a href=\"https:\/\/www.ssdnodes.com\/\" target=\"external\">our website<\/a>, and you can check out our <a href=\"https:\/\/blog.ssdnodes.com\/blog\/tutorial-setting-up-and-securing-ssh-based-authentication\/\" target=\"_blank\" rel=\"noopener\">How to access your server using SSH<\/a> guide to learn how to access your server and create a <code>sudo<\/code> user.<\/li>\n<\/ul>\n<h2>Step 1 - Updating your System<\/h2>\n<p>Before installing Python on Alamalinux, you first need to update the packages to the latest available versions using the following command:<\/p>\n<pre><code>sudo dnf update -y<\/code><\/pre>\n<p>Once the update is done, you should see the following output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9451\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/update.webp\" alt=\"python on almalinux: updates\" width=\"600\" height=\"345\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/update.webp 600w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/update-300x173.webp 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2>Step 2 - Installing Python on AlmaLinux 9<\/h2>\n<p>To install Python 3.12 on your AlmaLinux server, first install the packages necessary to build Python 3.12 using the following command:<\/p>\n<pre><code>sudo dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget make tar -y<\/code><\/pre>\n<p>You should see the following output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9452\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/Installed.webp\" alt=\"installing python on almalinux\" width=\"600\" height=\"271\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/Installed.webp 600w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/Installed-300x136.webp 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Next, download the Python 3.12 archive package from the official Python website with <code>wget<\/code>:<\/p>\n<pre><code>wget https:\/\/www.python.org\/ftp\/python\/3.12.3\/Python-3.12.3.tar.xz<\/code><\/pre>\n<p>Once the download finishes, extract the archive package using the <code>tar<\/code> command:<\/p>\n<pre><code>tar -xf Python-3.12.3.tar.xz<\/code><\/pre>\n<p>A new <code>Python-3.12.3<\/code> directory will appear, navigate to it using <code>cd<\/code>:<\/p>\n<pre><code>cd Python-3.12.3<\/code><\/pre>\n<p>Run the configuration file to check that all dependencies are available on your system:<\/p>\n<pre><code>.\/configure --enable-optimizations<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9453\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/optimizations.webp\" alt=\"python on almalinux 9\" width=\"600\" height=\"308\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/optimizations.webp 600w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/optimizations-300x154.webp 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>This check will take a few minutes. Once it finishes, use the <code>make<\/code> command to start building Python:<\/p>\n<pre><code>make -j 2<\/code><\/pre>\n<p><strong>Note:<\/strong> the <code>-j<\/code> flag sets the number of CPU cores the <code>make<\/code> command will use, it is recommended to use all the cores that are available in your server to speed up the build process, use the <code>nproc<\/code> command to get the number of cores you have on your server, and use that number in the command above.<\/p>\n<p>Once the build process finishes, run the following command to install the Python package on your system:<\/p>\n<pre><code>sudo make install<\/code><\/pre>\n<p>Now that Python 3.12 is installed on your AlmaLinux server, you can check your Python version by running the following command:<\/p>\n<pre><code>python3 -V<\/code><\/pre>\n<p>You'll receive your Python version:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9454\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/python-version.webp\" alt=\"Python on AlmaLinux version\" width=\"600\" height=\"178\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/python-version.webp 600w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/05\/python-version-300x89.webp 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>With this, you have Python installed on your AlmaLinux 9 server and you can now create a virtual environment.<\/p>\n<h2>Step 3 - Creating a Python Project Under a Virtual Environment<\/h2>\n<p>Python virtual environments allow you to have multiple isolated Python environments on one computer. This is useful for projects that require different versions of Python, or for projects that you don't want to contaminate with code from other projects. This ensures that each Python project is isolated from your other projects, so that conflict between dependencies does not occur.<\/p>\n<p>To create a Python programming environment, create a project directory somewhere in your system:<\/p>\n<pre><code>mkdir myproject<\/code><\/pre>\n<p>Navigate to your directory:<\/p>\n<pre><code>cd myproject<\/code><\/pre>\n<p>Then use the <code>python -m venv<\/code> command line to create a new virtual environment inside your project folder:<\/p>\n<pre><code>python3 -m venv env<\/code><\/pre>\n<p>This will create a new directory called <code>env<\/code>, which contains the dependencies you install while your virtual environment is activated. Here, we call this virtual environment directory <code>env<\/code>, which is a name commonly used for Python virtual environment directories, but you can change it to another name if you wish.<\/p>\n<p><strong>Note:<\/strong> You can create as many virtual environments as you want, and it is highly recommended to create a virtual environment for each new Python project.<\/p>\n<p>To use this new environment and isolate your code and dependencies from the main AlmaLinux system's Python installation, you need to activate it with the following command. Change <code>env<\/code> with the name of your virtual environment folder:<\/p>\n<pre><code>source env\/bin\/activate<\/code><\/pre>\n<p>Your command line should now have an <code>(env)<\/code> prefix indicating that your virtual environment is activated.<\/p>\n<p>To install a Python package using <code>pip<\/code>, you can use the following command:<\/p>\n<pre><code>pip install package<\/code><\/pre>\n<p>With <code>package<\/code> being the name of the Python package you wish to install.<\/p>\n<p>For example, to install the Django web framework, you can use the following command:<\/p>\n<pre><code>pip install django<\/code><\/pre>\n<p>With this, you now have a Python programming environment ready, and you can now manage your Python packages inside isolated virtual environments.<\/p>\n<h2>Step 4 - Creating a Small Python Program<\/h2>\n<p>With your virtual environment activated inside your project folder, you can now write Python code and install dependencies, and run them in an isolated box without interfering with the Python system installation on your AlmaLinux server.<\/p>\n<p>To edit files, you will need to first install the <code>nano<\/code> editor:<\/p>\n<pre><code>sudo dnf install nano -y<\/code><\/pre>\n<p>Once <code>nano<\/code> is installed on your system. You can now use it to edit Python files.<\/p>\n<p>Let's create a small Python program called <code>hi.py<\/code> that displays a <code>Hello, World!<\/code> text:<\/p>\n<pre><code>nano hi.py<\/code><\/pre>\n<p>Type the following code into it:<\/p>\n<pre><code>print(\"Hello, World!\")<\/code><\/pre>\n<p>Save and close the file by pressing <code>CTRL + X<\/code>, then <code>Y<\/code> and <code>ENTER<\/code>.<\/p>\n<p>Now, run the program using the <code>python<\/code> command:<\/p>\n<pre><code>python hi.py<\/code><\/pre>\n<p>You should receive the following output:<\/p>\n<pre><code>Hello, World!<\/code><\/pre>\n<p><strong>Note:<\/strong> To deactivate your Python programming environment, use the following command:<\/p>\n<pre><code>deactivate<\/code><\/pre>\n<p>With this, you now have a working programming environment for your Python projects.<\/p>\n<h2>Congrats!<\/h2>\n<p>In this tutorial, you've learned how to install Python on AlmaLinux, how to create a programming environment to isolate your Python projects, and how to install Python packages in it. You can learn more about Python by going through the <a href=\"https:\/\/docs.python.org\/3\/tutorial\/index.html\" target=\"_blank\" rel=\"noopener\">official Python tutorial<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>From Installation to Execution: A Comprehensive Guide to Setting Up and Using a Python Development Environment on AlmaLinux 9.<\/p>\n","protected":false},"author":19,"featured_media":9714,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[30],"tags":[213],"class_list":["post-9448","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-python"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/9448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/comments?post=9448"}],"version-history":[{"count":6,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/9448\/revisions"}],"predecessor-version":[{"id":12937,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/9448\/revisions\/12937"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/media\/9714"}],"wp:attachment":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/media?parent=9448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/categories?post=9448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/tags?post=9448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}