pip install -r requirements.txt
务必注意:基于【requirements.txt】文件中的全部库【可能某些库的版本依赖不一样】而导致无法安装成功,最好的方式就是把哪些【 需要更低版本依赖的库】先拿出来,等待文件安装成功之后,再单独安装即可【当单独使用 pip install 包名称】时,会自动匹配对应的版本【比如卸载新版本,然后安装匹配的旧版本依赖】
当你需安装的包 pip install 某个包名称,如果对应的依赖版本不一致,会自动匹配的!
Collecting idna>=2.0
Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Installing collected packages: idna, aiodns
Attempting uninstall: idna
Found existing installation: idna 3.2
Uninstalling idna-3.2:
Successfully uninstalled idna-3.2
Attempting uninstall: aiodns
Found existing installation: aiodns 3.0.0
Uninstalling aiodns-3.0.0:
Successfully uninstalled aiodns-3.0.0
Successfully installed aiodns-2.0.0 idna-2.10
大概的意思如下:
收集idna>=2.0
使用缓存的idna-2.10-py2.py3-non-any.whl (58 kB)
安装收集的软件包:idna, aiodns
试图卸载:idna
发现现有安装:idna 3.2
卸载 idna-3.2:
成功地卸载了idna-3.2
试图卸载: aiodns
发现现有安装:aiodns 3.0.0
卸载aiodns-3.0.0。
成功地卸载了aiodns-3.0.0
成功安装 aiodns-2.0.0 idna-2.10
基于pip批量安装包的方式,非常适合conda在不同的操作系统下迁移环境
第一步:使用【pip freeze > requirements.txt】全部的pip包复制到一个requirements.txt文件中
第二步:在目标操作系统下创建一个python环境【这里请指定版本】
第三步:使用【pip install -r requirements.txt】来批量安装pip的包!【注:如果发现某个包安装失败,请从requirements.txt删除后,再次执行批量安装,安装失败的包,请单独安装即可】
问题:为何要pip批量安装包的方式来更新有时候更方便:
1、因为conda在不同的操作系统下导入的yaml文件有些包【因为操作系统的不同】可能导致不兼容而安装失败
2、假如需要把python3.7 升级成python3.8或更高版本的环境,这样只需创建一个python3.8版本的环境,然后pip统一按照包即可,不会受制于之前python版本的限制!
参考conda 如何把python3.7的库 全部迁移升级为3.8更高的版本【或降低为py3.6更低的版本】:【重磅推荐】conda 如何把python3.7的库 全部迁移升级为3.8更高的版本【或降低为py3.6更低的版本】_比特币爱好者007的博客-CSDN博客_python3.7升级3.8