Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»Python»How to Install Python 3.9 on Amazon Linux 2

    How to Install Python 3.9 on Amazon Linux 2

    By RahulMay 7, 20233 Mins Read

    Python is a highly popular and versatile programming language, renowned for its simplicity, ease of learning, and wide range of applications, including web development, data analysis, and machine learning. The release of Python 3.9 brings several performance enhancements and new features, making it an attractive choice for developers.

    Advertisement

    In this tutorial, we will walk you through the process of installing Python 3.9 on Amazon Linux 2 systems using the source archive file. This method of installation provides you with greater flexibility and customization options, ensuring that your system is equipped with the most up-to-date version of Python.

    Prerequisites

    Installing Python from the source code requires a GCC compiler. So must have installed the required development libraries first.

    Open a terminal on your system and install the prerequisites for Python:

    sudo yum install gcc openssl-devel bzip2-devel libffi-devel 
    
    • Read: How to Use SSH to Connect Remote Linux Server

    Step 1 – Download Python 3.9

    Visit Python’s official download page and download the required Python on your system. Alternatively, You can use the following command to download Python 3.9 on a local machine.

    cd /opt 
    wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tgz 
    

    After the download is finished, extract the archive file.

    sudo tar xzf Python-3.9.16.tgz 
    

    Step 2 – Install Python 3.9

    Switch to the extracted directory with the cd command. Then use the ./configure script to prepare the source code. After that, you can compile and install it with the make command. Below set of commands to compile Python 3.9 from the source code and install using the altinstall command.

    cd Python-3.9.16 
    sudo ./configure --enable-optimizations 
    sudo make altinstall 
    

    make altinstall is used to prevent replacing the default python binary file /usr/bin/python.

    Now remove the downloaded source archive file from your system

    sudo rm -f /opt/Python-3.9.16.tgz 
    

    Step 3 – Check Python Version

    The Python 3.9 binary is installed under /usr/local/bin directory. As we have not overwritten the current Python version, you need to run Python 3.9 command as follows:

    python3.9 -V 
    
    Python 3.9.16
    

    Step 4 – Create Python Virtual Environment

    Python provides to create an isolated environment for the applications. Where you can create an environment directory with a specific Python version. This will contain application-specific packages.

    Use the following command to create an environment directory:

    python3.9 -m venv env 
    

    The above command will create a directory “env” in the current directory containing all the required files for the isolated environment.

    Every time you need to make changes in the environment, Use the below command to activate it.

    source env/bin/activate 
    

    After activating the environment, you can work with your application.

    Once your work is finished, use the following command to deactivate the Python environment.

    deactivate 
    

    Conclusion

    Throughout this tutorial, we have shown you the detailed steps to install Python 3.9 on Amazon Linux 2 using the source archive file. This approach allows for a more personalized installation experience, enabling you to take full advantage of Python 3.9’s improved performance and new features. As you continue to work with Python, consider exploring its extensive ecosystem of libraries and frameworks, which can further enhance your programming capabilities and project efficiency. With Python 3.9 now installed on your Amazon Linux 2 system, you are well-prepared to tackle a wide variety of programming tasks and build innovative, high-performance applications.

    Amazon Linux 2 Python Python3 Python3.9
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Setting and Getting the Default Timezone in Python

    Python Function with Parameters, Return and Data Types

    Understanding Python’s Underscore ( _ ): A Comprehensive Guide

    View 4 Comments

    4 Comments

    1. Paul Whipp on November 16, 2021 8:08 pm

      This is a good clear guide but on Amazon Linux, Python is build without ssl using this method which results in errors when trying to use pip etc.

      Reply
    2. d00m on August 17, 2021 6:59 pm

      sudo yum install sqlite-devel
      cd Python-3.9.6
      sudo ./configure –enable-optimizations –enable-loadable-sqlite-extensions
      sudo make altinstall

      Reply
      • Odin on December 30, 2022 2:16 am

        Thank you @d00m you saved the day

        Reply
    3. Max on June 10, 2021 7:17 pm

      Hey Rahul, thanks for the article. It worked for me, but when I tried to start a simple django app I got

      …
      File “/usr/local/lib/python3.9/sqlite3/__init__.py”, line 23, in
      from sqlite3.dbapi2 import *
      File “/usr/local/lib/python3.9/sqlite3/dbapi2.py”, line 27, in
      from _sqlite3 import *
      ModuleNotFoundError: No module named ‘_sqlite3’

      Looks like the latest django version requires sqlite 3.9, but in the Linux 2 only 3.7 installed. Do you know how to fix it?

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Setting and Getting the Default Timezone in Python
    • What is Media Access Control (MAC) Address?
    • What is Cross-Site Scripting (XSS)?
    • What is Content Security Policy (CSP)?
    • A User’s Guide to Understanding Redirection Operators in Bash
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.