Python Basic-Python source code installed to CentOS 7

1. Download the installation package

[root@Private python]#  mkdir -pv /usr/python/                                                                     #=================> 创建相应的目录

[root@Private python]# wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz                            #=================> bash 输入
--2020-04-19 09:05:36--  https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
Resolving www.python.org (www.python.org)... 151.101.228.223, 2a04:4e42:1a::223
Connecting to www.python.org (www.python.org)|151.101.228.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17869888 (17M) [application/octet-stream]
Saving to: ‘Python-3.8.2.tar.xz.1’

100%[============================================================================================================================================================================================>] 17,869,888  10.4KB/s   in 31m 7s  

2020-04-19 09:36:44 (9.35 KB/s) - ‘Python-3.8.2.tar.xz.1’ saved [17869888/17869888]

2. Unzip the installation package

1. Unzip the compressed package
[root @ Private python] # tar -Jxvf Python-3.8.2.2.tar.xz
2. View the decompressed file list
[root @ Private python] # ls Python-3.8.2 -l

Third, compile and install

[root @ Private Python-3.8.2] # yum -y groupinstall Development Tools (CentOS 7)
[root @ Private Python-3.8.2] # yum -y install zlib-devel xz bzip2 openssl openssl-devel
[root @ Private Python -3.8.2] # ./configure --enable-optimizations # You can use "--prefix = PREFIX" to specify the path to compile and install to the specified directory you need. This time it is not specified to install to the default directory. For more compilation and installation options, use "./configure -h" (need to be used in the source directory of the Python decompression) to view.
[root @ Private Python-3.8.2] # make
[root @ Private Python-3.8.2] # make install

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

4. Establish soft links (multiple versions can coexist)

Soft links have been created in the default installation, you can create other soft links according to your needs

[root@Private bin]# pwd
/usr/local/bin
[root@Private bin]# ls -l
total 13964
lrwxrwxrwx 1 root root        8 Apr 19 10:25 2to3 -> 2to3-3.8
-rwxr-xr-x 1 root root      101 Apr 19 10:25 2to3-3.8
-rwxr-xr-x 1 root root      241 Apr 19 10:25 easy_install-3.8
lrwxrwxrwx 1 root root        7 Apr 19 10:25 idle3 -> idle3.8
-rwxr-xr-x 1 root root       99 Apr 19 10:25 idle3.8
-rwxr-xr-x 1 root root      223 Apr 19 10:25 pip3
-rwxr-xr-x 1 root root      223 Apr 19 10:25 pip3.8
lrwxrwxrwx 1 root root        8 Apr 19 10:25 pydoc3 -> pydoc3.8
-rwxr-xr-x 1 root root       84 Apr 19 10:25 pydoc3.8
lrwxrwxrwx 1 root root        9 Apr 19 10:25 python3 -> python3.8
-rwxr-xr-x 1 root root 14269184 Apr 19 10:24 python3.8
-rwxr-xr-x 1 root root     3087 Apr 19 10:25 python3.8-config
lrwxrwxrwx 1 root root       16 Apr 19 10:25 python3-config -> python3.8-config

Five, configure environment variables

In the default installation, because the installation path is in / usr / local / bin, this path is already in the PATH environment variable, so there is no need to add an additional PATH here

[root@Private bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

If you need to manually change the PATH environment variable:
vim /etc/profile.d/python3.sh
export PATH = "$ PATH: your path"

Six, check the installed version

[root@Private bin]# python3 -V
Python 3.8.2

7. Execute the first program to print "Hello, World"

[root@Private bin]# python3
Python 3.8.2 (default, Apr 19 2020, 10:20:42) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello,World")
Hello,World
>>> 

Guess you like

Origin www.cnblogs.com/fei-huang/p/12720473.html