当前位置: 首页 > 科技观察

CentOS7安装使用Python3

时间:2023-03-12 21:41:49 科技观察

介绍在CentOS7上,默认安装了Python2,但是现在很多程序默认需要Python3才能正常运行。如果您使用系统的Python环境,当系统更新时,更新包可能会破坏依赖。最好的办法就是自己编译安装一个Python3,然后用虚拟环境来运行我们的Python程序。之所以使用虚拟环境,是为了让我们安装的Python3能够被多个程序使用,安装包不会相互冲突。编译安装时需要安装一些依赖包#!/bin/bashVERSION='3.10.0'yum-yinstallxztargccmaketk-develwgetsqlite-develzlib-develreadline-developenssl-develcurl-develtk-develgdbm-develxz-develbzip2-devellibffi-develcd/root/wget-chttps://mirrors.huaweicloud.com/python/${VERSION}/Python-${VERSION}.tgztarxvfPython-${VERSION}.tar.xzcdPython-${VERSION}./configure--prefix=/opt/python3makemakeinstallcho'exportPATH=/opt/python3/bin:$PATH'>>/etc/profile使用测试源/etc/profilepython3-Vsetmirrorsourcemkdir~/.pipcat>~/.pip/pip.conf<