Install Python3 and pip2 in CentOs

Today I installed CentOs 7 in the virtual machine. After the installation, I found that its own Python environment is only Python 2.7, and I need to install Python 3 myself. This is not as friendly as Ubuntu. I hope that it will bring Python 3 in the future.
At the end of pip2 installation,
first go to the official website to download the source package of Python 3. Skip manually. . .
After downloading, unzip it first:

Note that all the following commands are in the root environment because of some permission issues

tar -xzvf Python-3.6.5.tgz
xzvf Enter tar --help by yourself to view
entering Python-3.6.5:

cd Python-3.6.5
./configure --prefix=/usr/local/python3.6

To determine the installation directory, you can enter ./configure --help to view options

Start compiling and installing

make && make install

Forgot to say one thing, compilation requires gcc, so you must have already installed it.

yum install gcc
will report an error at the end of the compilation and installation, which means that a module is missing, which is probably the case, forgot to take a screenshot. . .

zipimport.ZipImportError: can't decompress data;zlib not avaliable
make: *** [install] Error 1
This is because Python needs to decompress something and needs this module, so go and install it:

After the installation of yum install zlib-devel
is completed, when you open Python 3, you will find that the up and down keys cannot be used. This is embarrassing. It turns out that there is a lack of a module to escape. These are historical reasons. If you are interested in trying it out, you can search for it. The solution is to install:

yum install readline-devel
make && make install again, you will find some problems in the make && make install process, I still don't have a screenshot. .
Install Python3 and pip2 in CentOs
This is the lack of some modules, but it doesn't matter if you don't need them. For the future, let's install them:
yum install bzip2-devel
yum install sqlite-devel
yum install gdbm-devel
yum install tk-devel

What is missing? You can find it in Baidu by comparing what appears on your computer.

Then proceed to make && make install, and no surprise this time you're done! But there's a big problem, you probably won't get into the interpreter by typing python3, because it doesn't get into the environment variables. Create a soft link:

enable python3 and pip3

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

Strange, why local will change color

Alright, here it is.
By the way, Python 2.7 in CentOs doesn't have pip to install by yourself.
There is no pip in the official repository of yum, so EPEL can be installed. I was confused about this thing at first, what is this?

Enterprise Linux Add-On Packages (EPEL) is a Fedora Special Interest Group to create, maintain, and manage a high-quality set of add-on packages for Enterprise Linux, including but not limited to Red Hat Enterprise Linux (RHEL), CentOS, Scientific Linux (SL), Oracle Linux (OL).

To put it bluntly, it is another warehouse with a lot of software in it. According to the instructions of this official tutorial:

This is for CentOs 7

After yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
all the way yes, run:

After yum install python-pip
, pip2 can be used normally.
For details, go to /usr/bin/ to view ls pip or ls python .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325279724&siteId=291194637