Home  >  Article  >  Operation and Maintenance  >  How to install python3.8 under Linux

How to install python3.8 under Linux

PHPz
PHPzforward
2023-05-22 19:16:123401browse

Compared with installing python under windows, installing python under Linux is actually a very difficult choice. The first thing to solve is which distribution version to choose. The Linux kernel is in the hands of the technical team, but the Linux distributions are in the hands of different companies. For different considerations, different companies package different applications, install different package managers, and implement different release strategies based on the Linux kernel, which leads to hundreds of releases. In the market, the flowers are becoming more and more eye-catching. The most common and difficult question for newbies is: Which Linux should I use?

This issue is not only a matter of opinion, but also a topic of discussion among friends. Diehard fans of each release version can continue to argue about it. In order to experience these well-known distributions, the author has installed countless versions on his computer and virtual machines. The final conclusion is:

  • If it is for development, choose ubuntu 18.04 LTS is the ultimate perfect choice

  • Do not install the server version. At the end of development, you still need to install the graphical interface, so it is best to choose the Desktop version

The following articles can be used as a reference for selection:

  • 7 Best Linux Rolling Distributions

  • CentOS will be terminated at the end of the year

Why not choose CentOS, because it will soon disappear from the sight of Chinese people. A year ago Red Hat announced that it would end offering free CentOS Linux at the end of this year. Subsequently, Red Hat once again reminded that CentOS Linux 8 will reach the end of its life cycle (End of Life, EoL) on December 31, 2021. CentOS is one of the Linux distributions. It is compiled from the Red Hat Enterprise Linux source code launched by Red Hat based on the open source code. Because it comes from the same source code, some servers that require high stability use CentOS instead of the commercial version of Red Hat Enterprise Linux. Last year, Red Hat announced that CentOS would become a platform suitable for development by DevOps personnel, rather than an operating system for stable server applications or VMs. The new platform is called CentOS Stream, and there will no longer be CentOS 9. Why not choose Archlinux, because it requires extremely high knowledge of Linux and is equivalent to manual assembly. Geento is even more difficult. After installing it, you don’t even know where the starting point is. Relatively speaking, there are multiple distributions based on Debian to choose from. Among them, the best one, the one with the widest user base, and the one that can get the most relevant support is still Ubuntu.

After deciding to use Ubuntu, we started the installation of python3.8. In order to better learn Python3.8 installation under Ubuntu, it is recommended that you use the cloud server node provided by the cloud service provider.

We do not recommend foreign cloud nodes, including those from Amazon and Microsoft, because they may not be available at any time. The advantage of using cloud nodes is that they are very easy to use, because cloud nodes:

  • You don’t have to bother installing Linux on your own computer, otherwise your computer will become bricked if you are not careful

  • The operating system has been installed

  • Similar to the Windows sandbox, if there is a failure in the installation or any problems occur during use, you can reset and restore it at any time Go to a pure operating system environment

  • Flexible billing is much more convenient than buying a physical machine yourself

  • There are often discounts, and you can Get a cost-effective ECS node at a low price

The following uses Huawei's cloud nodes as an example for demonstration.

(1)

Use ssh to log in to the cloud node. Windows comes with the ssh command, which can be used directly. To run powershell, enter the following command:

ssh tianbin@172.17.10.67
输入密码即可

If you feel that the powershell interface is simple, it is recommended to use MobaXterm Personal Edition, which is a feature-rich GUI interface terminal software with powerful functions and complete configurations, which is rare. Tool software. It is more convenient and easier to use than Xshell/Putty. Compared to SecureCRT which requires cracking, MobaXterm is free.

(2)

After logging in, a large number of configuration tools are required. Although from a security perspective, sudo should be used before all the following commands so that you can perform the work of a system administrator as an ordinary user, from a practical perspective, doing so is a waste of time. Therefore, after logging in, directly use the command "su" to switch to the root identity.

# 需要输入root的口令su# 配置sshd服务器,保证经常测试客户端,从而不断线
sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 60/g' /etc/ssh/sshd_config
sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 60/g' /etc/ssh/sshd_config

# 允许root用户登录
sed -i '$aPermitRootLogin yes' /etc/ssh/sshd_config

# 接来下切换apt的安装源,使用阿里云提供的镜像。普通的文章通常写的源是国内的大学,但在实际中,只有阿里云与华为云提供的镜像才又快又好
sed -i 's#http://security.ubuntu#https://mirrors.aliyun#g' /etc/apt/sources.list
sed -i 's#http://archive.ubuntu#https://mirrors.aliyun#g' /etc/apt/sources.list
sed -i 's#http://us.archive.ubuntu#https://mirrors.aliyun#g' /etc/apt/sources.list

# 开始更新软件源与软件信息
apt update && apt upgrade -y

# 开始安装python3.8,请严格按下述顺序安装,否则会出现意料之外的结果
apt install -y python3.8 python3.8-dev

# 由于ubuntu自带python2.7以及python3.6,所以在安装python3.8后让它成为主用
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 3
update-alternatives --config python

python --version
apt install -y python3-pip

python -m pip install --upgrade pip
pip --version

# 使用阿里云的pip源,绝大部分包可以从阿里云下载安装,即快又好,否则安装时间特别长
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip install --upgrade setuptools

At this point, the installation of python3.8 is completed. It should be noted that due to the design limitations of the ubuntu18.04 release version, do not try:

  • Delete python2.7, there are many operating system components that depend on it

  • Delete python3.6, there are many operating system components that depend on it

  • If you delete it forcibly, the entire operating system will become a brick

For ubuntu, the development toolbox includes:

  • awk/sed/grep Three Musketeers, if you don’t know these three commands when developing under Linux, it will be difficult.

  • vi/vim editing artifact, it’s a bit easy to get started. Difficult, but lifelong benefits

  • #To avoid difficulties caused by unfamiliarity with Linux commands, it is recommended to install the Linux version of VS Code. Since vscode is cross-platform, it is indeed extremely convenient.

The above is the detailed content of How to install python3.8 under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete