如果使用的是python包,可以使用pip命令一键导入,导出
导出依赖包为requirements.txt
pip freeze > requirements.txt
导入依赖包为requirements.txt
pip install -r requirement.txt
pip freeze > requirements.txt
命令输出文件中出现文件路径而非版本号
解决办法:
pip list --format=freeze > requirements.txt
conda批量导出包含环境中所有组件的requirements.txt文件
conda list -e > requirements.txt
如果使用Anaconda,则使用conda命令一键导入,导出
conda env export > environment.yml
conda批量安装requirements.txt文件中包含的组件依赖
conda install --yes --file requirements.txt
--------------------------------------------------------------------------
如果提示错误:
C:\Users\Administrator>conda env export >d:/environment.yaml
CondaEnvException: Unable to determine environment
Please re-run this command with one of the following options:
* Provide an environment name via --name or -n
* Re-run this command inside an activated conda environment.
解决办法 导出时候指定名字 默认的名字为root,该名字为虚拟环境起名,便于切换虚拟环境时候指定激活哪个虚拟环境
conda env export --name root >environment.yaml
# 激活新建的虚拟环境 activate root
或者
C:\Users\Administrator>conda env export --name root1 > environment1.yaml
C:\Users\Administrator>
推测:
指定用户名可能为了鉴权,导入时候也需指定用户名吧
导出的环境文件存放路径
C:\Users\Administrator\environment.yaml
————————————————
版权声明:本文为CSDN博主「腾云鹏A」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/studyvcmfc/article/details/116570487
-------------------------------------------------------------------
环境混用的另外一种解决方案:
环境混用怎么办?
在导出依赖到 requirement.txt 文件时会有一种尴尬的情况。
你的本地环境不仅包含项目 A 所需要的依赖,也包含着项目 B 所需要的依赖。此时我们要如何做到只把项目 A 的依赖导出呢?
pipreqs 可以通过扫描项目目录,帮助我们仅生成当前项目的依赖清单。
通过以下命令安装:
pip install pipreqs
运行:
pipreqs ./