Python依赖库离线安装

部署运行你感兴趣的模型镜像

1. 作用

对于无法联网的环境,无法直接安装新的 Python 依赖库,可在联网环境导出对应依赖库离线安装文件,再发送到无法联网的环境,使用 Python 虚拟环境进行安装

2. 联网环境操作(导出)

2.1. 获得离线安装文件

以下几步不需要执行,不需要虚拟环境,不需要提前下载,直接使用 pip download -r 就可以

requirements.txt 内容

urllib3==1.26.4
requests==2.31.0
pymilvus==2.3.4
urllib3==1.26.4
requests==2.31.0
openpyxl==3.1.3

以下参数作用

Linux 平台
Python 版本
仅下载二进制包(避免源码)

pip download -r requirements.txt -d ./packages_3.7 --platform manylinux2014_x86_64 --python-version 3.7.1 --only-binary=:all:

假如 requirements.txt 中只写依赖的库,不写具体版本也能支持

2.1.1. 版本尝试

  • 报错
ERROR: Ignored the following versions that require a different python version: 1.2.0 Requires-Python >=3.7.1; 1.2.1 Requires-Python >=3.7.1; 1.2.2 Requires-Python >=3.7.1; 1.2.3 Requires-Python >=3.7.1; 1.2.4 Requires-Python >=3.7.1; 1.2.5 Requires-Python >=3.7.1; 1.3.0 Requires-Python >=3.7.1; 1.3.1 Requires-Python >=3.7.1; 1.3.2 Requires-Python >=3.7.1; 1.3.3 Requires-Python >=3.7.1; 1.3.4 Requires-Python >=3.7.1; 1.3.5 Requires-Python >=3.7.1; 10.2.0 Requires-Python >=3.8; 10.3.0 Requires-Python >=3.8; 11.0.0 Requires-Python >=3.8; 11.1.0 Requires-Python >=3.8; 11.2.0 Requires-Python >=3.8; 11.2.1 Requires-Python >=3.8; 12.0.0 Requires-Python >=3.9; 13.0.0 Requires-Python >=3.9; 14.0.0 Requires-Python >=3.9; 14.1.0 Requires-Python >=3.9; 14.1.1 Requires-Python >=3.9; 2.1.0 Requires-Python >=3.8; 2.2.0 Requires-Python >=3.8; 2.2.1 Requires-Python >=3.8; 2.2.2 Requires-Python >=3.8; 2.2.3 Requires-Python >=3.8; 2.3.0 Requires-Python >=3.9; 2.3.5 Requires-Python >=3.8; 2.3.6 Requires-Python >=3.8; 2.3.7 Requires-Python >=3.8; 2.3.8 Requires-Python >=3.8; 2.32.0 Requires-Python >=3.8; 2.32.1 Requires-Python >=3.8; 2.32.2 Requires-Python >=3.8; 2.32.3 Requires-Python >=3.8; 2.4.0 Requires-Python >=3.8; 2.4.0 Requires-Python >=3.9; 2.4.1 Requires-Python >=3.8; 2.4.10 Requires-Python >=3.8; 2.4.11 Requires-Python >=3.8; 2.4.12 Requires-Python >=3.8; 2.4.13 Requires-Python >=3.8; 2.4.14 Requires-Python >=3.8; 2.4.15 Requires-Python >=3.8; 2.4.2 Requires-Python >=3.8; 2.4.3 Requires-Python >=3.8; 2.4.4 Requires-Python >=3.8; 2.4.5 Requires-Python >=3.8; 2.4.6 Requires-Python >=3.8; 2.4.7 Requires-Python >=3.8; 2.4.8 Requires-Python >=3.8; 2.4.9 Requires-Python >=3.8; 2.5.0 Requires-Python >=3.8; 2.5.1 Requires-Python >=3.8; 2.5.2 Requires-Python >=3.8; 2.5.3 Requires-Python >=3.8; 2.5.4 Requires-Python >=3.8; 2.5.5 Requires-Python >=3.8; 2.5.6 Requires-Python >=3.8; 2.5.7 Requires-Python >=3.8; 2.5.8 Requires-Python >=3.8; 4.25.0 Requires-Python >=3.8; 4.25.0rc1 Requires-Python >=3.8; 4.25.0rc2 Requires-Python >=3.8; 4.25.1 Requires-Python >=3.8; 4.25.2 Requires-Python >=3.8; 4.25.3 Requires-Python >=3.8; 4.25.4 Requires-Python >=3.8; 4.25.5 Requires-Python >=3.8; 4.25.6 Requires-Python >=3.8; 4.25.7 Requires-Python >=3.8; 5.26.0 Requires-Python >=3.8; 5.26.0rc1 Requires-Python >=3.8; 5.26.0rc2 Requires-Python >=3.8; 5.26.0rc3 Requires-Python >=3.8; 5.26.1 Requires-Python >=3.8; 5.27.0 Requires-Python >=3.8; 5.27.0rc1 Requires-Python >=3.8; 5.27.0rc2 Requires-Python >=3.8; 5.27.0rc3 Requires-Python >=3.8; 5.27.1 Requires-Python >=3.8; 5.27.2 Requires-Python >=3.8; 5.27.3 Requires-Python >=3.8; 5.27.4 Requires-Python >=3.8; 5.27.5 Requires-Python >=3.8; 5.28.0 Requires-Python >=3.8; 5.28.0rc1 Requires-Python >=3.8; 5.28.0rc2 Requires-Python >=3.8; 5.28.0rc3 Requires-Python >=3.8; 5.28.1 Requires-Python >=3.8; 5.28.2 Requires-Python >=3.8; 5.28.3 Requires-Python >=3.8; 5.29.0 Requires-Python >=3.8; 5.29.0rc1 Requires-Python >=3.8; 5.29.0rc2 Requires-Python >=3.8; 5.29.0rc3 Requires-Python >=3.8; 5.29.1 Requires-Python >=3.8; 5.29.2 Requires-Python >=3.8; 5.29.3 Requires-Python >=3.8; 5.29.4 Requires-Python >=3.8; 6.30.0 Requires-Python >=3.9; 6.30.0rc1 Requires-Python >=3.9; 6.30.0rc2 Requires-Python >=3.9; 6.30.1 Requires-Python >=3.9; 6.30.2 Requires-Python >=3.9; 6.31.0 Requires-Python >=3.9; 6.31.0rc1 Requires-Python >=3.9; 6.31.0rc2 Requires-Python >=3.9
ERROR: Could not find a version that satisfies the requirement pandas>=1.2.4 (from pymilvus) (from versions: 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)
  • 分析

以上有提示 requirement pandas>=1.2.4

https://pypi.org/project/pandas/1.2.4/
Requires: Python >=3.7.1

  • 解决

当前报错是因为 pip download -r 命令写的版本是 --python-version 3.7 ,修改为 3.7.1 后解决

3. 无法联网环境操作——Linux(导入)

3.1. 创建虚拟环境

cd /tmp/py_import/
python -m venv import_venv

3.2. 激活虚拟环境

可 cd 到对应目录通过相对路径执行,也可以不 cd 到对应目录直接使用绝对路径执行

source import_venv/bin/activate

3.3. 在虚拟环境中安装依赖

pip install --no-index --find-links=/tmp/packages_3.7 -r requirements.txt

requirements.txt 内容

requests
pymilvus
requests
openpyxl

3.4. 执行脚本验证

cd /tmp/python_dir
export PYTHONPATH=.

python idas_asr_embedding/concurrent_embedding_save_vector_db.py
python idas_asr_embedding/vector_db_query_count.py

3.5. requests 问题解决

python -c “import requests; print(requests.version)”
python -c “import urllib3; print(urllib3.version)”

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/py_import/import_venv/lib/python3.7/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/tmp/py_import/import_venv/lib/python3.7/site-packages/urllib3/__init__.py", line 42, in <module>
    "urllib3 v2.0 only supports OpenSSL 1.1.1+, currently "
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.1.0j  20 Nov 2018'. See: https://github.com/urllib3/urllib3/issues/2168

openssl version

OpenSSL 1.0.2k-fips  26 Jan 2017

查看当前环境使用的版本

pip 版本requestsurllib3
3.52.25.11.26.4
3.72.31.01.25.11

3.5.1. 版本验证

pip install urllib31.26.4 requests2.31.0

再次执行 python -c 正常执行

通过使用指定的版本解决

3.6. pymilvus 问题解决

python -c “import pymilvus; print(pymilvus.version)”

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pymilvus'

https://pypi.org/project/pymilvus/

Milvus version Recommended PyMilvus version
2.4.* 2.4.10

以下都是 Requires: Python >=3.8

https://pypi.org/project/pymilvus/2.4.10/
https://pypi.org/project/pymilvus/2.4.0/
https://pypi.org/project/pymilvus/2.3.8/
https://pypi.org/project/pymilvus/2.3.5/

以下是最后一个 Requires: Python >=3.7

https://pypi.org/project/pymilvus/2.3.4/

尝试安装 pymilvus 2.3.4 版本

4. 联网环境操作不需要执行的操作(导出)

4.1. 创建虚拟环境(可跳过)

cd D:\desktop\py_export
python -m venv export_venv

之后会创建目录 D:\desktop\py_export\export_venv

4.2. 激活虚拟环境(可跳过)

export_venv\Scripts\activate.bat

显示

(export_venv) D:\desktop\py_export>

where python 或 pip 可查看当前 venv 对应目录

以下操作不切换目录

4.3. 安装依赖(可跳过)

最早使用的,后续会有问题

pip install requests pymilvus

出现问题后修改

pip install urllib3==1.26.4 requests==2.31.0 pymilvus==2.3.4

4.4. 导出依赖列表(可跳过)

pip freeze > requirements.txt

您可能感兴趣的与本文相关的镜像

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值