Installation of python 3.8 Environment Using shell Script in CentOS7 of Recommendation

  • 2021-07-26 09:15:06
  • OfStack

1 key execution

Install the python 3.8 environment with the virtual machine 1 key, simply change the network adapter to nat mode (make sure the host can surf the Internet), then put the tar package in the/root directory and execute the script.

The script first uninstalls the original python2.7 environment of the system, then automatically changes the way of obtaining the address of the network card to dhcp, checks the network connectivity, changes the domestic yum source, then installs python3.8 environment, and finally installs python3.8. After the installation is completed, it prompts friendly output.

Download the shared tar package directly, including python 3.8 version of tar package and script files.

Link: Script and its tar package
Extraction code: 4b6w

Script content:


#!/bin/bash
echo " When used, the python Adj. tar Package placement /root/ Directory "
read -p " This script requires networking , If it is a virtual machine , Please change the network adapter to nat Mode " -t 2
echo
sed -i "s/BOOTPROTO=static/BOOTPROTO=dhcp/" /etc/sysconfig/network-ifcfg-ens33
ifdown ens33
ifup ens33
systemctl start network &>/dev/null
systemctl restart network &>/dev/null
if [ $? -eq 0 ];then
ip=`ifconfig ens33 | awk 'NR==2 {print $2}'`
echo " Get IP Address succeeded, address is $ip"
else
echo " Failed to get address , Please check the network situation by yourself "
exit 1
fi
ping -c 3 www.baidu.com &>/dev/null
if [ $? -eq 0 ];then
echo " Network Connection Successful , Start executing subsequent code "
else
echo " Network connection failed , Please check if the address is available "
exit 1
fi
cd /etc/yum.repos.d/
rm -rf *
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo &>/dev/null
yum clean all &>/dev/null
yum makecache &>/dev/null
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-dnssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-4-devel libpcap-devel xz-devel -y &>/dev/null
echo " Build a domestic yum Source success , Starting installation python Environment "
cd /root/
tar zxf Python-3.8.0a2.tgz &>/dev/null
cd Python-3.8.0a2/
./configure --prefix=/usr/local/python_3.8 &>/dev/null
if [ $? -eq 0 ];then
echo " Environment installation complete , Configuring python3.8"
else
echo " Error in environment installation , Please check that all dependency packages are installed "
fi
make -j 4 &>/dev/null
make install &>/dev/null
ln -s /usr/local/python_3.8/bin/* /usr/bin/
echo "python3.8 Installation completed at /usr/local/python_3.8"

Implementation effect:

Note: The following is the effect of connecting the terminal. If it is executed in a virtual machine, the Chinese will be displayed as a small white grid, but it will not affect its operation.

[root@test2 ~]# sh python3.8_install.sh
When using, put the tar package of python in the/root/directory
This script requires networking. For virtual machines, change the network adapter to nat mode
Successful acquisition of IP address, address 192.168. 125.130
The network connection is successful, and the subsequent code is started
The domestic yum source was successfully built, and the python environment is being installed
Environment installation complete, configuring python 3.8
python3.8 is installed at /usr/local/python_3. 8

After the installation is complete, test the use of the


[root@test2 ~]# python3
Python 3.8.0a2 (default, Mar 29 2020, 19:45:00) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello')
hello
>>> #Ctrl+d Quit 

Summarize


Related articles: