CentOS7离线安装Python3

这里写自定义目录标题

    • 1.Python离线依赖安装包准备及安装
    • 2.Python安装包准备及安装
    • 3.创建软连接
    • 4.检查
    • 5.离线安装第三方模块

1.Python离线依赖安装包准备及安装

# 1.在外网服务器上,下载依赖包,保存在 当前路径的 python3.8.3 目录下
yum install --downloadonly --downloaddir=./python3.8.3 zlib-devel bzip2-devel \
openssl-devel ncurses-devel  epel-release gcc gcc-c++ xz-devel readline-devel \
gdbm-devel sqlite-devel tk-devel db4-devel libpcap-devel libffi-devel

# 2.把从外网下载的依赖包,拷贝到内网,进行安装
rpm -Uvh ./*.rpm --nodeps --force

2.Python安装包准备及安装

# 1.Python安装包准备
wget --no-check-certificate https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz

# 2.安装
tar -zxvf Python-3.8.3.tgz -C /opt/
cd /opt/Python-3.8.3
# 将Python3安装到此目录下
./configure --prefix=/usr/local/bin/python3
# 编译和安装
make && make install

3.创建软连接

# 创建python3软连接
ln -s /usr/local/bin/python3/bin/python3 /usr/bin/python3
# 创建pip3的软连接
ln -s /usr/local/bin/python3/bin/pip3 /usr/bin/pip3

4.检查

[root@jenkins ~]# python --version
Python 2.7.5
[root@jenkins ~]# python3 --version
Python 3.8.3
[root@jenkins ~]#
[root@jenkins ~]# pip --version
pip 19.2.2 from /usr/lib/python2.7/site-packages/pip-19.2.2-py2.7.egg/pip (python 2.7)
[root@jenkins ~]#
[root@jenkins ~]# pip3 --version
pip 19.2.3 from /usr/local/bin/python3/lib/python3.8/site-packages/pip (python 3.8)

5.离线安装第三方模块

# 先将安装包下载
pip3 download requests

# 然后安装
# --no-index 参数告诉pip不要从网络上查找安装文件。
# --find-links=. 参数告诉pip在当前目录中查找安装文件。
pip install --no-index --find-links=. requests

原文链接,根据此文修改:
https://blog.csdn.net/Happy_Sunshine_Boy/article/details/123180678

你可能感兴趣的:(python)