Build python3 environment in linux server

Yum downloads slowly, modify it to a domestic mirror:

Backup current yum source

mv /etc/yum.repos.d /etc/yum.repos.d.backup
Create a new yum source setting destination

mkdir /etc/yum.repos.d
set up Ali yum mirror

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo to
rebuild the cache

yum clean all
 
yum makecache
At this time, ping www.baidu.com should be no problem. If yum still has problems, the domain name cannot be resolved, so configure as follows

vim /etc/resolv.conf

nameserver 8.8.8.8
nameserver 114.114.114.114

Start to install Python3 version

1. You can use the linux built-in download tool wget to download, as shown below (the command to install the wget service: yum install wget):

The author installs the minimal CentOS system, so before using the compilation command, you must install the wget service, execute the installation command to install the wget service, and you can skip installing wget and proceed directly to the following compilation steps if you have used the compilation tool. If the reader does not know whether the wget service is installed in the CentOS system, you can use the wget command to check whether the wget service is installed.

 

 

 

2. After the download is complete, go to the download directory and decompress the downloaded file (use command: tar-zxvf Python-3.6.5.tgz)

 

3. After the pressurization is completed, enter the decompression directory: cd Python-3.6.5/

 

4. Before installing Python3, create a folder or directory python3 in /usr/local (as the installation path of python, so as not to overwrite the Python2 version)

mkdir /usr/local/python3 (The mkdir command is used to create a new folder here, or use the touch command if it is a new file)

 

5. Check whether the compilation suite gcc is installed (install the gcc compilation suite using command: yum install gcc)

The above display indicates that the gcc compilation kit is not installed, so you must install the compilation kit gcc before using the compile command. If you have installed the gcc compilation kit or have used the compilation tool, you can skip installing gcc and proceed directly to the following compilation steps.

 

Configure the installation path: ./configure --prefix=/usr/local/python3

 

Compile: make

 

Installation: make install

 

6. At this time, the old version is not overwritten, and the original /usr/bin/python link is changed to another name (the author keeps two versions, one python and one python3, so the author skips the sixth step and changes the seventh After the link of the step, the name is changed to python3, readers can follow the normal steps, and the effect is the same)

mv /usr/bin/python /usr/bin/python_old2

 

7. Create a link to the new version of python

ln -s /usr/local/python3/bin/python3.6  /usr/bin/python3

 

8. Enter this time: python -V

 

9. Matters needing attention:

If you do not create a new installation path python3, but install it directly by default, the new python after installation should overwrite the old version that comes with linux, or it may not, depending on the installation process.

You can test this yourself. Of course, if you want to keep the original version, then this method is best.

 

10. No ssl appears in pip install

 

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel 
readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

Recompile python

 

make
make install 

Guess you like

Origin blog.csdn.net/Growing_hacker/article/details/98361716