Choose a different version or distribution
Introduction
Before we begin talking about how to install Python 3.7 on Ubuntu 22.04, let's briefly understand – What is Python?
Python is a powerful and versatile programming language that is widely used for various purposes. It is known for its simplicity and readability, making it ideal for beginners. Python's extensive library ecosystem allows developers to access pre-built functions and tools, saving time and effort.
It supports multiple platforms, making it highly flexible. Python is commonly used for web development, data analysis, artificial intelligence, and automation. Its popularity and ease of use make it a valuable language for both experienced programmers and newcomers to coding.
In this tutorial, you will install Python 3.7 on Ubuntu 22.04. We will also address a few FAQs on how to install Python 3.7 on Ubuntu 22.04.
Advantages of Python
- Simplicity: Python's clear and concise syntax makes it easy to learn and read, ideal for beginners and experienced programmers alike.
- Versatility: Python can be used for a wide range of applications, including web development, data analysis, machine learning, and automation.
- Extensive Libraries: Python offers a vast collection of libraries that provide ready-to-use functions and tools, accelerating development time.
- Platform Compatibility: Python runs seamlessly on major operating systems, including Windows, macOS, and Linux, ensuring cross-platform compatibility.
- Community and Support: Python has a large and active community that provides extensive support, resources, and documentation, fostering collaboration and learning.
Prerequisites to Install Python 3.7 on Ubuntu 22.04
To install packages on your Ubuntu system, you must be logged in as root or a user with sudo access.
Installing Python 3.7 on Ubuntu with Apt
Installing Python 3.7 on Ubuntu with apt
is a simple process that will only take a few minutes:
1) Start by installing the prerequisites and updating the package list:
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev wget libbz2-dev
2) After that, add the deadsnakes PPA to your sources list:
sudo add-apt-repository ppa:deadsnakes/ppa
When prompted, click Enter
to proceed:
Output
Press [ENTER] to continue or Ctrl-c to cancel adding it.
3) After the repository has been enabled, install Python 3.7 using:
sudo apt install python3.7
4) Python 3.7 is now installed and ready to use on your Ubuntu system. You can check it by typing:
python3.7 --version
Output
Python 3.7.3
Installing Python 3.7 on Ubuntu from Source
We will demonstrate how to download and compile Python 3.7 in this section.
1) First, install the packages required to compile the Python source and update the packages list:
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev wget libbz2-dev
Use the wget command listed below to download the source code of the latest release from the Python download page:
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
At the time of writing this tutorial, the most recent release is 3.7.4
.
3) Unzip the gzipped tarball after the download is finished:
tar -xf Python-3.7.4.tgz
4) Next, head over to the Python source directory and launch the configure
script, which will conduct a series of checks to make sure all of your system's dependencies are available:
cd Python-3.7.4
./configure --enable-optimizations
The --enable-optimizations
option will optimize the Python binary by running numerous tests. This slows down the building process.
5) Using make
, begin the Python build process:
make -j 8
Modify the -j
flag in accordance with your processor for a faster build time. If you are unsure about your processor's core count, you can find it by typing nproc
. We are using the -j8
flag because the system used for this tutorial has 8 cores.
6) Once the build is complete, use the following command to install the Python binaries:
sudo make altinstall
It is recommended to not use the standard make install
, as it will overwrite the default system python3 binary.
7) All done. Python 3.7 has been installed and is ready to use. Type the following command to confirm:
python3.7 --version
The output will display the Python version:
Output
Python 3.7.4
FAQs to Install Python 3.7 on Ubuntu 22.04
Can I have multiple Python versions installed on Ubuntu 22.04?
Yes, Ubuntu allows you to have multiple Python versions installed simultaneously. You can switch between them using virtual environments or specifying the version explicitly.
How do I verify if Python 3.7 is installed?
Open the terminal and type python3.7 --version
. If Python 3.7 is installed correctly, it will display the version number.
Can I uninstall Python 3.7 later if needed?
Yes, you can uninstall Python 3.7 by running the command: sudo apt remove python3.7
. However, be cautious as this may affect any applications relying on Python 3.7.
Will installing Python 3.7 affect the system's default Python version?
No, installing Python 3.7 will not affect the system's default Python version (usually Python 2.7). It will be installed alongside the default version.
Can I still use the 'python' command to run Python 3.7 after installation?
No, the python
command typically refers to the default Python version (Python 2.7). To run Python 3.7, you need to use the python3.7
command.
Are there any additional packages or dependencies required for Python 3.7?
The installation process should handle most dependencies automatically. However, if you encounter any issues, you may need to install the required packages manually.
Can I install Python packages using pip with Python 3.7?
Yes, after installing Python 3.7, you can use pip to install Python packages specifically for Python 3.7 by using the pip3.7
command.
Conclusion
Hope this detailed tutorial helped you understand how to install Python 3.7 on your Ubuntu 22.04 system and are ready to start using it to develop your Python 3 project.
Following that, you can read about How to Use PIP and How to Create Python Virtual Environments for various Python projects.
If you have any queries, feel free to drop a comment below, and we'll be happy to help.