Centos 安装python3.8
Centos7 自带有 python,版本是 python2.7
Linux 安装 python3,需要先下载源码,然后编译
yum update
yum -y install gcc
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
mkdir /app
cd /app
网页:https://www.python.org/downloads/source/
执行下面命令下载 Python-3.8.13 的源码
wget https://www.python.org/ftp/python/3.8.13/Python-3.8.13.tgz
tar -zxvf Python-3.8.13.tgz --no-same-owner
进入目录:
cd Python-3.8.13
指定安装目录
安装到 /usr/local/python3 目录下:
./configure --prefix=/usr/local/python3
注意:不要加 --enable-optimizations 参数
编译并安装
make && make install
出现如下输出代表安装成功
Installing collected packages: setuptools, pip
Successfully installed pip-21.1.1 setuptools-56.0.0
清空缓存
如果编译错误,需要先清空缓存,再编译
make clean
目的:
输入 python3 命令,可以进入python3的环境
输入 pip3 命令,可以给python3安装库
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
进入Python3
用python3命令进入Python3
python3 --version
用pip3安装库
pip3 install
pip升级
pip3 install --upgrade pip