针对已经编译并且安装好python或者anaconda环境的情况
前期准备
1.需要一台可连接外网的服务器
2.安装相关依赖:
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make
3.在外网服务器安装需要版本的python(python 下载在官网寻找对应版本下载即可)
4.将对应python包解压
(case: python3.10.9.tar.gz -->tar -zxvf python3.10.9.tar.gz 解压 --> python3.10.9目录)
5.在python3.10.9目录编译 生成python3.10.9环境
./python3.10.9/configure --prefix=/usr/local/pyhton3.10.9
make
make install
公网下载
case :下载pandas包
/usr/local/python3.10.9/bin/pip3.10 download -d /root/package pandas
默认下载最新版本wheel或者tar.gz 到 /root/package/ 路径下
查看有哪些版本
/usr/local/python3.10.9/bin/pip3.10 download -d /root/package pandas==
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
ERROR: Could not find a version that satisfies the requirement pandas== (from versions: 0.1, 0.2, 0.3.0, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.6.0, 0.6.1, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.15.2, 0.16.0, 0.16.1, 0.16.2, 0.17.0, 0.17.1, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 0.19.2, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 0.23.1, 0.23.2, 0.23.3, 0.23.4, 0.24.0, 0.24.1, 0.24.2, 0.25.0, 0.25.1, 0.25.2, 0.25.3, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.4.0rc0, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.5.0rc0, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 2.0.0rc0, 2.0.0rc1, 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.1.0rc0, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.2.0rc0)
指定版本
/usr/local/python3.10.9/bin/pip3.10 download -d /root/package pandas==2.1.2
指定多个包;携带版本
/usr/local/python3.10.9/bin/pip3.10 download -d /root/package pandas requests pyhs2
/usr/local/python3.10.9/bin/pip3.10 download -d /root/package pandas==2.1.2 requests==1.0.0 pyhs2==0.11.0
/root/package 目录压缩为tar.gz的包
tar -zcvf package.tar.gz /root/package
离线安装
1.下载package.tar.gz 上传到离线服务器并进行解压
2.确认当前服务器python环境版本与公网下载时环境一致
3.安装(假设为root用户)
pip3 install /root/package/*
QA
1.出现版本冲出报错
case : 依赖numpy包版本为1.26.3 过高报错
ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
scipy 1.7.3 requires numpy<1.23.0,>=1.16.5, but you have numpy 1.23.5 which is incompatible.
解决:需要重新安装指定版本区间对应的包
2.有些依赖包为tar.gz 后缀的依赖包安装报错
case : 安装 word2vec.tar.gz
no matching distribution found for setuptools>=42
/usr/local/python3.10.9/bin/pip3.10 download -d /root/setuptools_scm setuptools_scm
打包/root/setuptools_scm/ --> tar -zcvf setuptools_scm.tar.gz /root/setuptools_scm/ --> setuptools_scm.tar.gz
上传文件并解压 tar -zxvf setuptools_scm.tar.gz
执行安装
pip3 install /root/setuptools_scm/setuptools_scm*.wheel
解决: 手动解压 word2vec.tar.gz -->tar -zxvf word2vec.tar.gz -->word2vec 目录
执行安装
cd word2vec
python setup.py install
3.缺失需要yum源安装的工具包依赖
case :sasl包相关的 --cyrus-sasl-plain cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-md5
在公网服务器下载相应的rpm 文件到 /home/package/ 目录
yum install --downloadonly --downloaddir=/home/yum_package/ cyrus-sasl-plain cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-md5
打包/home/py_package/ tar -zcvf yum_package.tar.gz /home/yum_package/ --> yum_package.tar.gz
上传文件并解压 tar -zxvf yum_package.tar.gz
执行安装
rpm -ivh ./yum_package/*.rpm --nodeps