Software Testing | Python Installation and Configuration Guide under Linux

Installing Python in Linux is a simple yet important process because Python is a widely used programming language and many system tools and applications rely on it. In this article, I will explain in detail how to install Python in Linux system.

Note that in this article I will use Centos as an example, but most of these steps will apply to other RedHat-based distributions as well. For other distributions, please use the corresponding package management tool to perform similar operations.

The default download under centos is python2.7 and needs to be replaced with 3.x. Currently, most applications are based on pyhton3, but many beginners are not familiar with the process of installing Python on Linux, so we need to install Python in the docker container. It can also be confusing at times, so today we will introduce the tutorial on installing and configuring Python under Linux.

Check installed version

First, let us check if Python is already installed on the system. The command is as follows:

python3 --version

If Python is already installed, we will see the version number of Python. Otherwise, a command not found or similar error message will appear. As shown below:

In addition to the built-in Python2.7, Python3.6 is also installed.

Download and unzip the installation package

We want to install Python3.8 in the system. First we need to download the Python installation package. The steps are as follows:

  1. Visit the Python official website to view the python download address: www.python.org/downloads/,…

Insert image description here

  1. Copy the link and use wgetthe command to download, as follows:
wget https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz

Execute the command, as shown below, and the compressed package of Python 3.8.8 will start to be downloaded.

Insert image description here

  1. After the download is complete, unzip the compressed package with the following command:
tar -zxvf Python-3.8.8.tgz

After decompression is completed, as shown below:

  1. Enter the Python-3.8.8 folder and run the following command:
cd Python-3.8.8
  1. Configuration, the command is as follows:
./configure --prefix=/root/Python-3.8.8
  1. To compile, the command is as follows:
make && make install

Configure environment variables

  1. We can first establish a soft link between Python3.8.8 and pip3.8. The command is as follows:
# python3.8 软链接
ln -s /root/Python-3.8.8/bin/python3.8 /usr/bin/python3.8

# pip3.8 软链接

ln -s /root/Python-3.8.8/bin/pip3.8 /usr/bin/pip3.8

  1. After establishing the soft link, we can test whether it is successful, switch directories, enter the following command, and view the results:
python 3.8

pip3.8

  1. To configure Python3.8 environment variables, the command is as follows:
cat >> /root/.bashrc << "EOF"
> export PATH=/root/Python-3.8.8/bin:PATH
> EOF

Note: This command requires pressing the Enter key once per line.

  1. Update the environment variable configuration file with the following command:
source /root/.bashrc

Verify the environment variable configuration, the command is as follows:

python3.8 --version

Run the command, the result is as follows:

Summarize

This article mainly introduces the process of installing Python3 environment under Linux system and configuring environment variables. I hope it can help everyone to complete the environment configuration under Linux more quickly and improve our work efficiency.

Finally, I would like to thank everyone who reads my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it directly:

This information should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you!

Guess you like

Origin blog.csdn.net/2301_78276982/article/details/135427978