Linux离线安装Python
一、环境
1,系统:CentOS 7
2,用户:root
3,Python版本:python3.8.12
二、安装
1,在有外网的环境下,下载好安装包和依赖
下载Python3的安装包
访问https://www.python.org/ftp/python/,下载合适的安装包
下载依赖:
yumdownloader --destdir=/home/packages zlib zlib-devel bzip2-devel epel-release ncurses-devel mpfr libmpc kernel-headers glibc glibc-common glibc-headers glibc-devel cpp gcc libffi-devel libgcc libgomp libstdc++ libstdc++-devel gcc-c++
注:使用 yumdownloader 命令 需先安装yum-utils
2,登录到centOS机器,新建文件夹
mkdir /usr/local/python3
将安装包和依赖包里的文件上传至/usr/local/python3
3,进入目录
cd /usr/local/python3/
4,安装依赖
rpm -Uvh --force --nodeps *rpm
(rpm -Uvh ***.rpm)
5,进行解压
tar -xzvf Python-3.8.12.tgz
6,进入解压路径
cd /usr/local/python3/Python-3.8.12
7,设置安装路径
./configure --prefix=/usr/local/python3.8 --enable-shared
make && make install
ln -s /usr/local/python3.8/bin/python3 /usr/bin/python3
echo "/usr/local/python3.8/lib" > /etc/ld.so.conf.d/python3.8.conf
ldconfig
8,检查Python3.8.12是否安装成功
python3 -V
显示如下图,说明成功;
三、安装pip3
1,python 3.8.12中自带了pip,所以只需要建立链接就行
ln -s /usr/local/python3.8/bin/pip3.8 /usr/bin/pip3
2,检查pip是否安装成功
pip3 -V
出现如下图,表示正常: