编程语言
首页 > 编程语言> > python pip下载本地依赖包,并在离线环境中安装,并解决报错ERROR: Could not find a version that satisfies the requirement报错

python pip下载本地依赖包,并在离线环境中安装,并解决报错ERROR: Could not find a version that satisfies the requirement报错

作者:互联网

文章目录

整体思路如下:

  1. 首先根据项目需要导出依赖包,由于本地的python环境中其实安装了很多乱七八糟的包,这些包不一定都用得上,因此只需要导出必要的依赖就可以
  2. 根据当前项目的依赖清单,下载对应的安装包,以便在新的python环境中可以直接离线安装这些
  3. 进入到新环境中离线安装即可

步骤1:导出依赖

首先在当前环境下安装:pip install pipreqs,这个库可以帮助你筛选出项目需要的python包,而不是当前环境的全部依赖。安装完成后使用命令:

cd 项目根目录/
pipreqs ./ --encoding=utf-8

在根目录下会生成requirements.txt文件,我的内容如下:

itemadapter==0.1.0
selenium==3.141.0
Scrapy==2.3.0
python_dateutil==2.8.2
........

步骤2:离线下载依赖包

然后根据requirements.txt导出需要的安装包

pip download -d PIPDIR -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com 

有几个常用配置:

注意:这里一定要添加--trusted-host,否则会报错:

WARNING: The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host mirrors.aliyun.com'.
ERROR: Could not find a version that satisfies the requirement xxx==xxx (from versions: none)
ERROR: No matching distribution found for xxx==xxx

步骤3:进入新环境使用python安装依赖

根据自己的实际情况,把这个文件夹和requirements.txt移动到新的环境中,然后使用:

pip install --no-index --find-links=PIPDIR -r requirements.txt

标签:requirement,依赖,python,离线,--,报错,pip,txt,安装
来源: https://blog.csdn.net/weixin_35757704/article/details/120595248