Learn to install Python3 under Linux in three minutes (with video tutorial)

Installation video:

Learn to install python3 on linux in three minutes

foreword

In our daily work, study and life, there are three common systems: Windows, Mac, and Linux. The common ones for Linux include Redhat, Ubuntu, and Centos.

There is nothing to talk about installing Python on Windows and Mac. Go to the official website to download the corresponding installation package, double-click until the next step and the installation is complete. In the case of Linux installation, the steps are slightly more complicated, mainly reflected in two aspects: the time-consuming compilation and installation and the need to install the dependent environment in advance.

Linux is usually used the most is Centos, one is open source and free, and the other is easy to operate, so here is based on Centos to demonstrate the installation process.

Install Python

Python3.8 is installed here.

1. Dependency module installation

Before compiling and installing, some dependent modules need to be installed. The command is as follows:

yum -y install zlib zlib-devel libffi-devel
yum -y install bzip2 bizp2-devel 
yum -y install ncurses ncurses-devel
yum -y install readline readline-deval
yum -y install openssl openssl-devel openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel

I was lazy and didn't install some dependencies before, and an error will be reported when compiling. Even if the compilation is passed, it will prompt that there are missing modules when installing some python packages, so install it honestly.

2. Upgrade gcc

This step can actually be omitted. But if optimization is enabled during compilation, if the gcc version is too old, it must be upgraded.

The upgrade command is as follows:

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
gcc -v

Here, you can see my gcc version:

3. Download, compile, install

Official website address: https://www.python.org , the website is a little slow, please wait patiently.

Here we download version 3.8. The installation command is as follows:

# 下载
wget https://www.python.org/ftp/python/3.8.13/Python-3.8.13.tar.xz
# 解压
tar xvf Python-3.8.13.tar.xz

cd Python-3.8.13
# prefix指定安装目录,enable-optimizations启动优化参数
./configure --prefix=/usr/local/python --enable-optimizations
# 编译安装
make & make install

4. Create a soft link

Linux soft links are equivalent to windows shortcuts.

cd /usr/local/bin
ln -s /usr/local/python3/bin/python3.8 python3
ln -s /usr/local/python3/bin/pip3 pip3

Here you can also add python to the PATH to achieve the above functions.

5. Verification

Execute python3 and enter the command line environment, which means the installation is successful.

epilogue

In this way, the installation of python under Linux is completed, and the operation is relatively simple, except that the compilation and installation process is time-consuming.


Post-95 young programmers, write about personal practice in daily work, from the perspective of beginners, write from 0 to 1, detailed and serious. The article will be published on the public account [ Getting Started to Give Up Road ], looking forward to your attention.

Thank you for every encounter

Guess you like

Origin blog.csdn.net/CatchLight/article/details/124598480