Linux Tactic

Two Ways to Install Python 39 on Ubuntu

Installing Python 3.9 on Ubuntu: From Apt and Source

Python is a popular dynamic programming language that is used across various industries for building software, developing web applications, analyzing data, and more. Ubuntu, one of the most popular Linux distributions, comes with built-in Python support.

However, it might not be the latest version, which is Python 3.9. That’s where you might need to install the latest version of Python 3.9 on your Ubuntu system. In this article, we will look into two ways to install Python 3.9 on Ubuntu from Apt and from Source.

Installing Python 3.9 on Ubuntu with Apt

Updating and Installing Prerequisites

The first step before installing Python 3.9 is to update your Ubuntu system and install the necessary dependencies. You can do this by running the following commands:

“`

$ sudo apt-get update

$ sudo apt-get install software-properties-common

“`

Adding the Deadsnakes PPA

Next, you need to add the Deadsnakes Personal Package Archive (PPA) to your system. The PPA provides various Python versions, including Python 3.9. You can add the PPA by running the following command:

“`

$ sudo add-apt-repository ppa:deadsnakes/ppa

“`

Installing Python 3.9

After adding the PPA, you need to update your system again to get the latest package lists.

You can do this by running:

“`

$ sudo apt-get update

“`

Finally, you can install Python 3.9 by running the following command:

“`

$ sudo apt-get install python3.9

“`

Verifying the Installation

Once the installation is complete, you can verify the version of Python by running:

“`

$ python3.9 –version

“`

And that’s it! You have successfully installed Python 3.9 on Ubuntu using Apt. Installing Python 3.9 on Ubuntu from Source

If you prefer to build Python from source, here are the steps to follow:

Downloading the Python 3.9 Source Code

First, you need to download the Python source code from the official website.

You can use the following command to download the tarball:

“`

$ wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz

“`

Extracting the Gzipped Archive

After downloading the tarball, you need to extract its contents. You can use the following command to extract the contents in the same directory:

“`

$ tar -xvzf Python-3.9.5.tgz

“`

Running the Configure Script

The next step is to run the configure script, which checks for any missing dependencies and sets up the build environment. You can run the script using the following command:

“`

$ cd Python-3.9.5

$ ./configure –enable-optimizations

“`

The script will take some time to run and might show some errors related to missing dependencies.

If you encounter any errors, you can install the missing dependencies and re-run the configure script. Building Python 3.9

After running the configure script, you can proceed to build Python 3.9 by running the following commands:

“`

$ make -j

“`

The “-j” option tells make to use multiple cores for building, which speeds up the build process significantly.

You can replace “” with the number of cores on your system.

Installing the Python Binaries

After building Python, you can install the binaries using the following command:

“`

$ sudo make altinstall

“`

The “altinstall” command installs Python 3.9 alongside any existing Python versions, without replacing them.

Verifying the Installation

Finally, you can verify the installation by running the following command:

“`

$ python3.9 –version

“`

And that’s it! You have successfully installed Python 3.9 on Ubuntu from source.

Conclusion

Installing Python 3.9 on Ubuntu can be done in two ways – from Apt and from Source. Both methods have their pros and cons, and which one to choose depends on your preferences and requirements.

Installing from Apt is easier, faster, and automated, but you might not have control over the build process. On the other hand, building from source gives you complete control over the installation process, but requires more time, effort, and familiarity with the build process.

Installing Python 3.9 on Ubuntu 20.04

Ubuntu is one of the most popular Linux distributions, and Ubuntu 20.04 is the latest long-term support (LTS) release. It comes with Python 3.8, but if you need Python 3.9, you can install it using the methods we discussed in the previous sections.

In this section, we will cover some additional information about installing Python 3.9 on Ubuntu 20.04.

Availability in Standard Ubuntu Repositories

The easiest way to install Python 3.9 on Ubuntu 20.04 is to use the standard Ubuntu repositories. However, as of writing this article, Python 3.9 is not available in the standard repositories of Ubuntu 20.04.

It is expected to be available in Ubuntu 21.04, which is the next version of Ubuntu to be released. If you want to install Python 3.9 on Ubuntu 20.04, you can use the methods we discussed in the previous sections, such as using a PPA or building from source.

Starting a Python 3.9 Project

If you want to start a new Python project with Python 3.9, there are a few things you need to consider. First, make sure you have Python 3.9 installed on your system, either by using the methods we discussed earlier or by using a Python distribution like Anaconda or Miniconda.

Next, you can create a new virtual environment for your project using a tool like virtualenv or conda. Here are the steps to create a new virtual environment using virtualenv:

“`

$ python3.9 -m venv myenv

$ source myenv/bin/activate

“`

The first command creates a new virtual environment called “myenv” using Python 3.9. The second command activates the virtual environment, which makes the Python interpreter and package manager use the packages installed in the virtual environment instead of the system-wide packages.

After creating the virtual environment, you can install the required packages for your project using pip, the default Python package manager. You can create a requirements file that lists all the required packages and their versions, and then install them using the following command:

“`

$ pip install -r requirements.txt

“`

In the requirements file, you can specify the version of Python you are using, like this:

“`

python==3.9.5

“`

This ensures that anyone who wants to run your project also has Python 3.9.5 installed.

Conclusion

Installing Python 3.9 on Ubuntu 20.04 requires some extra work since it is not available in the standard repositories. However, using a PPA or building from source are both viable options.

Once you have Python 3.9 installed, you can start a new project using a virtual environment and the required packages. Python 3.9 comes with many new features and improvements, such as performance enhancements, new syntax, and new modules, which make it a great choice for developing modern Python applications.

In summary, installing Python 3.9 on Ubuntu can be done through either Apt or Source, each with its own advantages and disadvantages. Python 3.9 is not currently available in the standard Ubuntu 20.04 repositories, but it is still possible to install it.

Starting a new Python 3.9 project involves creating a virtual environment and installing the necessary packages. Python 3.9 offers many new features and improvements, making it a great choice for developing modern Python applications.

The ability to install and use the latest version of Python is crucial for developers needing access to the newest language features and capabilities for innovating modern applications.

Popular Posts