Python Examples
Convert IP to Integer and Integer To IP in Python How to Get IPv4/IPv6 Address Range from CIDR in Python? Compare Two Objects For Equality in Python How to find Duplicate Elements from a List in Python Convert Timestamp to datetime in Python Convert datetime to Timestamp in Python Generate Random String of Specific Length in Python Encryption and Decryption of Strings in Python The string module in Python Convert string to bytes in Python Convert bytes to string in Python Convert string to datetime and datetime to string in Python Call a function Asynchronously from within a Loop and wait for the Results in Python Remove Duplicate Elements from a List in Python Caching in Python with Examples How to Bulk Insert and Retrieve Data from Redis in Python How to Write Unit Test in Python Read and Write CSV Files in Python Read and Write Data to a Text File in Python How to Convert CSV to JSON in Python Create ICS Calendar File in Python Install Python on Windows 10/11 Install Python on Ubuntu 20.04 or 22.04.3 Python - Install Virtual Environment How to Find a Specific Field Value from a JSON list in Python Download and Unzip a Zipped File in Python Python Install PIP Python Install Virtual Environment How to Fix Python Error: string argument without an encoding Compare Two JSON files in Python How to Hash a Dictionary Object in Python? Create a Digital Clock in Python Create Multiple URLs Using Each Path of a URL in Python Send an Email with Multiple Attachments using Amazon SES in Python SQLAlchemy Query Examples for Effective Database Management SQLAlchemy Query to Find IP Addresses from an IP Range in Bulk How to Create and Use Configuration files in a Python Project Check if a Value Already Exists in a List of Dictionary Objects in Python How to Split Large Files by size in Python? Fixing - Running Scripts is Disabled on this System Error on Windows Generating QR Codes in Python Reading QR Codes in Python

Install Python on Ubuntu 20.04 or 22.04.3

  • Last updated Apr 25, 2024

Python can be installed on Ubuntu either using apt via terminal or using source code.

Installing Python on Ubuntu is very simple and will only take a few minutes. If you already have other versions of python installed then it is recommended that you do not remove them, as there are many system packages of Ubuntu, such as Graphical Display Manager that provides graphical login is dependent on the default python 2. Uninstalling the default python may cause the Graphical Display Manager failed.

You can have many versions of Python on your system. During software development, you can choose which version of Python to use.

Installing Python using apt via Terminal
  1. Start by updating the package information using the following command:
  2. sudo apt update
  3. Now, install Python3.12 using the following command:
  4. sudo apt-get install python3.12
  5. Verify the installed version of Python using the following command:
  6. python3.12 --version
Installing Python using Source Code
  1. Start by installing the following prerequisites one by one:
  2. sudo apt-get install build-essential checkinstall
    
    sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
    
  3. Use wget Command to download the latest stable version of Python from the Python's official site. At the time of writting this tutorial, the latest stable version of Python was 3.12.
  4. sudo wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz
    
  5. After the download is complete, extract the gzipped tarball file:
  6. tar -xf Python-3.12.0.tgz
    
  7. Next, navigate inside the Python directory and execute the script to enable Python optimizations as shown below:
  8. cd Python-3.12.0
    sudo ./configure --enable-optimizations
    
  9. Configure the number of processors to make the Python build time faster. This is done by modifying the -j as shown below. My system has 8 cores so I am using 8. You can find the number of cores your system has by typing nproc:
  10. make -j 8
    
  11. After the configuration is complete, install Python binaries. Do not use the standard make install command as it will override the default system binary of python 3:
  12. sudo make altinstall
    
  13. After the installation is complete, remove the downloaded tar file to free space:
  14. cd ..
    sudo rm -f Python-3.12.0.tgz
    
  15. Next, verify if the Python is installed successfully:
  16. python3.12 --version
    

    You must see the version of Python:

    Python 3.12.0