Linux一键安装Python3.11.2
前言
生产过程中难免会用到python,但是linux自带的python好像是2.7.5的,有点落后了,所以今天教大家怎么在linux服务器中安装python3.11.2
教程
首先随便在一个目录下创建一个文件夹,并且上传python3.11.2的安装包然后输入以下命令
tar zxvf python-3.11.2.tgz
在python-3.11.2
目录下创建一个文件,命名为python311_install.sh
,并将以下代码放入其中
#!/bin/bash
# You should have Internet connection.
# You should have Online yum resource, if you don't have Online yum resource, Please use below
function online_yumresource() {
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
}
function py311_install() {
yum -y groupinstall "Development tools"
yum install -y ncurses-devel gdbm-devel xz-devel sqlite-devel tk-devel uuid-devel readline-devel bzip2-devel libffi-devel
yum install -y openssl-devel openssl11 openssl11-devel
yum install centos-release-scl
yum -y install devtoolset-8
source /opt/rh/devtoolset-8/enable
echo "source /opt/rh/devtoolset-8/enable" >> /etc/profile
gcc --version
export CFLAGS=$(pkg-config --cflags openssl11)
export LDFLAGS=$(pkg-config --libs openssl11)
tar zxvf Python-3.11.2.tgz
cd Python-3.11.2
./configure --enable-optimizations
make && make altinstall
ln -sf /usr/local/bin/python3.11 /usr/bin/python3
ln -sf /usr/local/bin/pip3.11 /usr/bin/pip3
# Create a virtual environment and activate it
python3.11 -m venv myenv
source myenv/bin/activate
# Upgrade pip and install other packages
pip install --upgrade pip
pip install numpy pandas matplotlib
}
online_yumresource
py311_install
然后再在终端中输入如下命令
cd python-3.11.2 && sh python311_install.sh
结语
可以在终端中输入python3 --version
,如果显示python 3.11.2
就说明安装成功了。
教程到此结束
提示:本文最后更新于2024年 2月 11日,如有错误或者已经失效,请留言告知。
THE END