CentOS7 install python3.6 (detailed)

Before installation, download the python3.6 package from the official website. I am using the Python-3.6.5 source package here.

1.安装依赖环境
yum -y install gcc zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

2. Unzip the source code package
tar -zxvf Python-3.6.5.tgz

3. After decompressing the source code package, a directory will be generated, enter this directory to compile the source code installation
cd Python-3.6.5
configuration:
./configure --prefix=/usr/local/python3 -----> Specify the installation directory

Install after compiling:
make && make install

4. Make python3 soft link (easy to use)
delete the original python soft link:
cd /usr/bin/
rm -f python

Make a soft link for python3:
ln -s /usr/local/python3/bin/python3 /usr/bin/python

Make pip3 soft link:
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

5. The yum command is written in python2, so you need to modify the interpreter in yum to python2
vim /bin/yum
#!/usr/bin/python2 ----->The interpreter is #!/usr/bin/python Change to #!/usr/bin/python2

vim /usr/libexec/urlgrabber-ext-down
#!/usr/bin/python2 ----->The interpreter is changed from #!/usr/bin/python to #!/usr/bin/python2

Guess you like

Origin blog.csdn.net/weixin_44901564/article/details/108344012
Recommended