Use shell script to install python3.8 environment in CentOS7 (recommended)

Use shell script to install python3.8 environment in CentOS7 (recommended)

One-click execution

To install Python 3.8 in a virtual machine, you only need to change the network adapter to NAT mode (make sure the host can access the Internet), then put the tar package in the /root directory and execute the script.

The script first uninstalls the system's original python2.7 environment, then automatically changes the way the network card obtains the address to dhcp, checks network connectivity, changes the domestic yum source, then installs the python3.8 environment, and finally installs python3.8. After the installation is complete, a friendly output is prompted.

Just download the shared tarball, which contains the python 3.8 version tarball and script files.

Link: Script and its tarball Extraction code: 4b6w

Script content:

#!/bin/bash
echo "Put the python tarball in the /root/directory when using it"
read -p "This script requires an Internet connection. 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 "Successfully obtained IP address, address is $ip"
else
echo "Failed to obtain address, please check the network status 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 "The domestic yum source has been successfully built, and the Python environment is being installed"
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 completed, configuring python3.8"
else
echo "Environment installation error, please check whether all dependent 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, located in /usr/local/python_3.8"

Implementation effect:

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

[root@test2 ~]# sh python3.8_install.sh
When using, put the python tarball in the /root/directory. This script requires an Internet connection. If it is a virtual machine, please change the network adapter to NAT mode. Successfully obtain the IP address, the address is 192.168.125.130
The network connection is successful, and the subsequent code is executed. The domestic yum source is successfully built, and the python environment is being installed. The environment installation is complete, and python3.8 is being configured.
Python 3.8 is installed and is located at /usr/local/python_3.8

After installation, test using

[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 to exit

Summarize

This is the end of this article about using shell scripts to install python3.8 environment in CentOS7. For more information about installing python3.8 environment in centos7, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Centos8 (minimum installation) tutorial on how to install Python3.8+pip
  • Install the latest python3.8 under Centos7
  • VirtualBox CentOS7.7.1908 Python3.8 build Scrapy development environment [graphic tutorial]
  • Detailed tutorial for installing python3.8.2 in CentOS

<<:  Detailed explanation of how to use Vue self-nested tree components

>>:  Introduction to MySQL triggers, creation of triggers and analysis of usage restrictions

Recommend

WeChat applet implements text scrolling

This article example shares the specific code for...

Issues with upgrading Python and installing Mongodb drivers under Centos

Check the Python version python -V If it is below...

Detailed explanation of Angular component life cycle (I)

Table of contents Overview 1. Hook calling order ...

Shtml Concise Tutorial

Shtml and asp are similar. In files named shtml, s...

Solution to the error when importing MySQL big data in Navicat

The data that Navicat has exported cannot be impo...

The use of MySQL triggers and what to pay attention to

Table of contents About Triggers Use of triggers ...

Django online deployment method of Apache

environment: 1. Windows Server 2016 Datacenter 64...

In-depth analysis of the Tomcat server of Centos 7 system

Table of contents 1. The origin of tomcat 1. Tomc...

Linux five-step build kernel tree

Table of contents 0. The kernel tree that comes w...

Tips for implementing list loop scrolling based on jQuery (super simple)

I saw a good idea and recorded it. I have used jQ...

Comparison of the use of form element attributes readonly and disabled

1) Scope of application: readonly:input[type="...

MySQL stored procedure in, out and inout parameter examples and summary

Stored Procedures 1. Create a stored procedure an...

Web page layout should consider IE6 compatibility issues

The figure below shows the browser viewing rate i...

How to deeply understand React's ref attribute

Table of contents Overview 1. Creation of Refs ob...

Linux installation MySQL5.6.24 usage instructions

Linux installation MySQL notes 1. Before installi...