Linux下已经默认安装Python2,本文记录如何安装Python3
安装步骤
下载一个合适的Python安装包
可以从浏览器下载好安装包,然后拷贝到Linux环境下。下载地址:https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz当然, 也可以直接在Linux下下载
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
解压安装包
tar -zxvf ./Python-3.8.6.tgz
创建安装目录
mkdir -p /usr/local/python3
指定安装位置为先前设置目录
cd ./Python-3.8.6
./configure --prefix
=/usr/local/python3
编译并安装
yum -y
install zlib zlib-devel
bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel
yum
install gcc
make && make install
验证一下
cd /usr/local/python3/bin
python3 -V
/usr/local/python3/bin/python3 -V
想全局用?添加一个软连接到/usr/bin下即可
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
python3 -V
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
写在后面
当然如果想在crontab定时任务或rc.local中使用Python3启动脚本, 直接用全路径即可。
done