CentOS quickly install Python3 and pip3

CentOS is one of the Linux systems that are often used, especially as a server. It only comes with Python2, but now Python3 is more widely used, so you need to install it yourself. At the same time, in order to install third-party libraries more conveniently, you need to install it. pip3.

One, install related dependencies##

  1. The installation environment depends on:
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
  1. Install the gcc compiler (it may already be installed)
yum install gcc -y

Two, install Python3

Take Python3.7 as an example to explain.

  1. Download the Python installation package
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz

Because the download is slow, you can download it locally and upload it to the server in a faster way.

  1. Move the installation package to the /usr/local folder
mv Python-3.7.4.tgz /usr/local/
  1. Create a Python3 directory in the local directory
mkdir /usr/local/python3
  1. The directory where the Python installation package compressed package is entered
cd /usr/local/
  1. Unzip the installation package
tar -xvf Python-3.7.4.tgz
  1. Enter the unzipped directory
cd /usr/local/Python-3.7.4/
  1. Configure the installation directory
. /configure --prefix=/usr/local/python3
  1. Compile the source code
make
  1. Perform source installation
make install

In this step, the error ModuleNotFoundError: No module named'_ctypes' may appear. This is because the dependency package libffi-devel is missing. For the solution, please refer to https://blog.csdn.net/CUFEECR/article/details/103093951.

  1. Create soft connection
ln -s /usr/local/python3/bin/python3  /usr/bin/python3
  1. test
    Type python3 to print:
Python 3.7.4(default, Sep  62020,09:22:23)[GCC 4.8.520150623(Red Hat 4.8.5-39)] on linux
Type "help","copyright","credits" or "license"for more information.>>>

That means that Python is installed successfully.

Two, install pip3

  1. Installation dependencies (not necessary)
sudo yum install openssl-devel -y 
sudo yum install zlib-devel -y
  1. Install setuptools
# Download the installation file
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26

# Unzip
tar -zxvf setuptools-19.6.tar.gz 
cd setuptools-19.6

# Perform installation
sudo python3 setup.py build 
sudo python3 setup.py install
  1. Install pip3
# Download the installation file
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-20.2.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
 
# Unzip
tar -zxvf pip-20.2.2.tar.gz 
cd pip-20.2.2

# Perform installation
python3 setup.py build 
sudo python3 setup.py install
  1. test
    After the installation is complete, enter pip3 -V and print:
pip 20.2.2from/usr/local/python3/lib/python3.7/site-packages/pip(python 3.7)

It means that the installation is successful and the required third-party libraries can be installed normally. Please note:
It should be pip3 xxx instead of pip xxx when used, to distinguish it from Python2.

Recommended Posts

CentOS quickly install Python3 and pip3
CentOS7 install python3 and pip3
centos7 install python3 and ipython
CentOS 6.9 compile and install python
Centos6 install python3 pip3 ipython3
CentOS 6 compile and install python 3
Centos6 install Python2.7.13
Centos7 install Python 3.6.
CentOS install Python 3.6
Centos7 install Python2.7
Install Python3 and ansible under CentOS8
Centos install Python3
Install Python3 and Py under CentOS7
CentOS6.8 install python2.7
Install centos7 and connect
Know Linux and install CentOS
CentOs7.3 compile and install Nginx 1.9.9
ubuntu18.04 compile and install python3.8
CentOS6.5 install Java 8 and Tomcat8
Centos compile and install Git
Centos 6.10 reinstall python and yum
Centos6.5 install and configure mongodb
CentOS7 install OracleJDK and JRE
CentOS6.5 install Java 8 and Tomcat8
CentOS6 install and crack Jira 7
CentOS6.5 install Java 8 and Tomcat8
Centos7 compile and install ntp-4.2.8p11
CentOS6 install and crack confluence
CentOS6 install and crack Jira 7
Centos 7 install jdk and package service service
CentOS7 yum install and start mysql
Install and configure keepalived under CentOS 5.9
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
CentOS 8 install Git and basic configuration
CentOS 6.x compile and install Nginx
CentOS7 compile and install L(A|N)MP environment
CentOS7.3 install iptables and detailed use
How to install Python 3.8 on CentOS 8
CentOS7 yum install and start mysql
CentOS 8 - install and configure NFS service
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Centos7 uninstall openJdk, and install JDK1.8
How to install Python on CentOS 8
Install and use docker under CentOS 6.8
1.5 Install Centos7
CentOS7 install and use SQL Server
Configure python3 environment on centos7 and
CentOS Minimal install and configure TIPS
Centos 7.5 python3.6
Install and configure FreeIPA in Centos7
Linux CentOS6 compile and install Pyt
virtualBox install centos, and build tomcat
Install Mono 3.2 and Jexus 5.4 under CentOS 6.3
Compile and install libmodbus library under CentOS7
CentOS7.5 source code compile and install mysql5.7.29
Centos7 compile and install MySQL8 problem record
Centos python3 compile installation and compile gcc upgrade
R&D: How To Install Python 3 on CentOS 7
Install Mono 2.10.8 and Jexus 5.0 under 32- and 64-bit CentOS 6.0
Python and scrapy deployment in centos environment