How to Install Python 3.8 on CentOS 8

[ad_1]

Python is one of the most widely used programming languages in the world. With its simple and easy to learn syntax, Python is a popular choice for beginners and experienced developers. Python is quite a versatile programming language. It can be used to build all kinds of applications, from simple scrips to sophisticated machine learning algorithms.

CentOS 8 includes Python version 3.6
, which can be installed or updated using the dnf tool.

At the time of writing, Python 3.8 is the latest major release of the Python language. It includes many new features such as assignment expressions, positional-only parameters, f-strings support, and more
. Python 3.8 is not available in the standard CentOS 8 repositories.

This guide explains how to build Python 3.8 on CentOS 8 from the source code. We’ll also show you how to create a virtual environment.

Installing Python 3.8 on CentOS 8 #

Compiling Python from source requires C/C++ compiler and other dev packages. The first thing to do is to install the packages necessary to build Python from the source code on CentOS 8. To do so, run the following commands as root or sudo user
:

sudo dnf groupinstall 'development tools'
sudo dnf install bzip2-devel expat-devel gdbm-devel     ncurses-devel openssl-devel readline-devel wget     sqlite-devel tk-devel xz-devel zlib-devel libffi-devel

Download the latest release’s source code from the Python download page
using wget
. Currently, the latest Python 3.8 release is 3.8.1. If there is a new version available for download, change the VERSION variable in the command below:

VERSION=3.8.1wget https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tgz

When the download is complete, extract the gzipped archive
:

tar -xf Python-${VERSION}.tgz

Change to the Python source directory and run the configure script which performs a number of checks to make sure all of the dependencies on your system are present:

cd Python-${VERSION}./configure --enable-optimizations

The --enable-optimizations option optimizes the Python binary by running multiple tests. This makes the build process slower.

Start the Python 3.8 build process by running:

make -j 4

Modify the -j to correspond to the number of cores in your processor. You can find the number by typing nproc.

Once the build process is complete, install the Python binaries:

sudo make altinstall

Please do not use the standard make install as it will overwrite the default system python binary.

That’s it. Python 3.8 has been installed on your CentOS system, and you can start using it. Verify it by typing:

python3.8 --version

The output should show the Python version:

Python 3.8.1

Creating a Virtual Environment #

Python virtual environment is a self-contained directory tree that includes a Python installation and a number of additional packages. It allows you to install Python modules in an isolated location for a specific project, rather than being installed globally. This way, you do not have to worry about affecting other Python projects.

First, create the project directory and switch
to it:

mkdir ~/my_app && cd ~/my_app

From inside the project root run the following command to create a virtual environment named my_app_venv:

python3.8 -m venv my_app_venv

Activate the environment:

source my_app_venv/bin/activate

Once activated, the shell prompt will be prefixed with the name of the environment. Starting with Python 3.4, when creating virtual environments pip, the package manager
for Python is installed by default.

Within the virtual environment, you can use pip instead of pip3.8 and python instead of python3.8:

python -v
Python 3.8.1

Once you are done with your work to deactivate the environment, type deactivate and you will return to your normal shell.

deactivate

Conclusion #

We have shown you how to install Python 3.8 on your CentOS 8 machine and how to create a virtual environment. You can now start developing your Python 3 projects.

If you have any questions or feedback, feel free to comment below.

[ad_2]

Source link

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.