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.
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
yum install gcc -y
Take Python3.7 as an example to explain.
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.
/usr/local
foldermv Python-3.7.4.tgz /usr/local/
mkdir /usr/local/python3
cd /usr/local/
tar -xvf Python-3.7.4.tgz
cd /usr/local/Python-3.7.4/
. /configure --prefix=/usr/local/python3
make
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.
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
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.
sudo yum install openssl-devel -y
sudo yum install zlib-devel -y
# 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
# 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
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