CentOS7 next upgrade version of Python

Park to blog first blog, later to adhere to develop a record share of habit ah, this life will have traces of ~


Server version: CentOS 7.3 64 Wei

Old Python Version: 2.7.5

New Python Version: 3.8.0

Description: The user performs an operation using the root configuration, it is not used sudo statements in the code, use the non-root note


 1, switching to the working directory / usr / local

In the Linux system, the path / usr / local equivalent to the C: / Progrem Files /, this directory will be installed when the software is typically installed.

Excuting an order:

cd /usr/local

2, download the compressed version of the target python

Excuting an order:

wget http://npm.taobao.org/mirrors/python/3.8.0/Python-3.8.0.tgz

Here, I'm using python in the country's image, if you want to use the official website address is of course also possible, but the speed is two to say ...

3, extracting archive

Excuting an order:

cross -xzf Python- 3.8 . 0 .tgz

4, in the current directory to create a folder --python3

Excuting an order:

mkdir python3

5, compile and install

Steps:

a. Go to unzip the file path

Python- cd 3.8 . 0

b. produce the makefile

./configure --prefix=/usr/local/python3

c. to operate the makefile

make

d. Install

make  install

Command interpreter:

  • When the source code in Linux by the installer, for extracting files, execute ./configure, after the implementation of make, make install the final implementation

    make the makefile command is operating, make install commands to install, then ./configure is doing it? ./configure in fact produce the makefile

- Reference " Wen Chao "

  • --prefix role: to specify when compiling the program storage path.

    Do not specify a prefix, the executable file in the default / usr / local / bin, the default library file in / usr / local / lib, the default configuration file in / usr / local / etc, other resource files in / usr / local / share

    Specifies the prefix, delete a folder directly enough

- Refer to " Baidu know "

problem:

In this process, there is a problem installation failure:

zipimport.ZipImportError: can't decompress data; zlib not available

This is caused by the lack of dependence, perform the following codes:

yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel

- Refer to " Han Jue "

6, two versions of the configuration methods

Methods on configuring python version is roughly divided into two kinds :

  1. Python3 directly create soft, use the command python3 call the new version of the python, python comes with no conflict
  2. Overwrite an existing python, python to point to the new installation, use the command python can call the new version of python

Involved Command Interpreter

  • ln command to create a link to a file, type the link into hard links and symbolic (soft) link two kinds of default connection type is hard-wired. If you want to point to python3.8 create a symbolic link must use the "-s" option, a symbolic link is a shortcut under Windows, which can achieve start python
ln -sab # establish a flexible connection, b pointing to a

- Refer to " Yen "

The following two methods were introduced.

6.1 directly create soft python3

Creating python3 soft in / usr / bin path, point python3 installed

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

Creating pip3 soft in / usr / bin path, point pip3 installed

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

At this point there are two versions of python systems:

Command python corresponding still the default version 2.7

Command  python3  then the corresponding new version 3.8 installed,

This will be the end of this this method, you can happily play python3  -V, -V PIP3 view the corresponding version

6.2 overwrite existing python, the start point python3.8 python

Backup old python and pip

 Music Videos / usr / bin / Python / usr / bin / python2_old
  Music Videos / usr / bin / PIP / usr / bin / pip2_old # third portion of the file name may be modified in accordance with the native version

Modify soft links

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

This method has completed half of it here, you can use the command python -V, pip -V View version

According to " hold up sailing experience", should also be modified to point easy_install, you may use (not verified) use python3, can be modified based on the "Edit soft links" approach when used

6.2.1 finishing work

Since the modified version of the python, cause some programs that depend on old versions of error, such as yum , do as follows:

Open the file yum

vim /usr/bin/yum

The first line in the following figure:

 The python modify the old version, here to add 2.7:

 But still error when installing the software:

SyntaxError: invalid syntax
  File "/usr/libexec/urlgrabber-ext-down", line 28
  except OSError, e:

Or because of the replacement of python, in accordance with the above operation to modify the file: Open the / usr / libexec / urlgrabber-ext -down file, # / usr / bin / python!    Modified to # / usr / bin / python2.7!   

If other tools or libraries during the installation process also reported a similar error, the same law.

At this point the system still exist two versions of python, but the command python  corresponds to the newly installed version 3.8, command  python2 default before the 2.7 version only correspondence
this method here came to an end!


 In addition to the paper listed refer to the article, the main reference articles are:

https://blog.csdn.net/bawenmao/article/details/80216516

https://blog.csdn.net/u011798443/article/details/80825817

Thank you, above you!

Guess you like

Origin www.cnblogs.com/ech2o/p/11748464.html