比较两个 anaconda 安装之间的包
Posted
技术标签:
【中文标题】比较两个 anaconda 安装之间的包【英文标题】:Compare packages between two anaconda installations 【发布时间】:2019-06-04 17:35:48 【问题描述】:我的 Mac 上安装了两个版本的 Python,即 Anaconda,3.5 和 3.7。有什么方法可以知道我在 3.5 中安装了哪些在 3.7 中没有的软件包,例如可以使用 pip 安装的软件包(pulp、wordcloud 等)。
到目前为止我尝试过的是使用命令行:
diff -rq anaconda/.../python3.5/site-packages anaconda3/.../python3.7/site-packages
这显示了目录之间的差异,但显示了很多重复的包和核心模块的信息。如何找到两个 Anaconda 版本之间的包差异?
【问题讨论】:
可以使用pip3.5 list
和pip3.7 list
,然后比较输出。
感谢@Mowshon 真正有帮助。对额外过滤重复包(如 astropy 或 conda)有什么想法吗?
【参考方案1】:
您可以使用conda list
列出特定环境下安装的所有软件包。此外,您可以将列表导出到带有标志--export
的文件。
例如,如果您的环境名为 python3
和 pytorch_p36
,您可以执行以下操作:
conda list -n python3 --export > python3-packages.txt
conda list -n pytorch_p36 --export > pytorch_p36-packages.txt
diff python3-packages.txt pytorch_p36-packages.txt
该命令还接受标志--json
,它将以json格式导出数据,适合自动处理。
【讨论】:
嘿@Julian Peller 感谢您的回复。我试过了,但我面临着额外的麻烦。我不知道如何指定环境名称。我使用 conda info --envs 寻找它们。它表明其中一个称为 /anaconda3,另一个称为 /anaconda。因此,当我输入 conda list -n anaconda 时,会出现一个错误,告诉您没有这样的环境。如果您能给我任何提示,我将不胜感激。 @julian peller 激活环境conda activate myenv
,然后您可以获得与该环境相关的信息【参考方案2】:
感谢 dataista 为您提供的 Linux 解决方案。对于 Windows diff 不起作用,但在 Windows 中可以使用 FC:
conda list -n python3 --export > python3-packages.txt
conda list -n pytorch_p36 --export > pytorch_p36-packages.txt
FC python3-packages.txt pytorch_p36-packages.txt
【讨论】:
【参考方案3】:最近的一项开发现在提供了将 conda 环境与需求文件进行比较的能力。到目前为止,我发现的唯一提及这一点的是在 2020 年 7 月 16 日合并的 pull request。我可以验证 compare
命令在 conda 版本 4.8.4 中有效。需要注意的是,输出中只列出了差异。
用法:
(ProcMCD43A1) C:\Users\justincase>conda compare environment.yml --json
[
"argon2-cffi found but mismatch. Specification pkg: argon2-cffi==20.1.0=py37he774522_1, Running pkg: argon2-cffi==20.1.0=py37h4ab8f01_1",
"attrs found but mismatch. Specification pkg: attrs==19.3.0=py_0, Running pkg: attrs==20.2.0=pyh9f0ad1d_0",
"backcall found but mismatch. Specification pkg: backcall==0.2.0=py_0, Running pkg: backcall==0.2.0=pyh9f0ad1d_0",
"bleach found but mismatch. Specification pkg: bleach==3.1.5=py_0, Running pkg: bleach==3.2.0=pyh9f0ad1d_0",
"brotlipy found but mismatch. Specification pkg: brotlipy==0.7.0=py37he774522_1000, Running pkg: brotlipy==0.7.0=py37h4ab8f01_1000",
"bzip2 found but mismatch. Specification pkg: bzip2==1.0.8=he774522_0, Running pkg: bzip2==1.0.8=he774522_3",
"cffi found but mismatch. Specification pkg: cffi==1.14.0=py37h7a1dbc1_0, Running pkg: cffi==1.14.3=py37h26f1ce3_0",
"cfitsio found but mismatch. Specification pkg: cfitsio==3.470=he774522_5, Running pkg: cfitsio==3.470=hbbe6aef_6",
"cftime found but mismatch. Specification pkg: cftime==1.2.1=py37h2a96729_0, Running pkg: cftime==1.2.1=py37h44b1f71_0",
"chardet found but mismatch. Specification pkg: chardet==3.0.4=py37_1003, Running pkg: chardet==3.0.4=py37hc8dfbb8_1006",
"click not found",
"click-plugins not found",
"cligj not found",
"cryptography found but mismatch. Specification pkg: cryptography==2.9.2=py37h7a1dbc1_0, Running pkg: cryptography==3.1=py37h26f1ce3_0",
"curl found but mismatch. Specification pkg: curl==7.67.0=h2a8f88b_0, Running pkg: curl==7.71.1=h4b64cdc_5",
"cycler found but mismatch. Specification pkg: cycler==0.10.0=py37_0, Running pkg: cycler==0.10.0=py_2",
"descartes not found",
"entrypoints found but mismatch. Specification pkg: entrypoints==0.3=py37_0, Running pkg: entrypoints==0.3=py37hc8dfbb8_1001",
"fiona not found",
"freexl found but mismatch. Specification pkg: freexl==1.0.5=hfa6e2cd_0, Running pkg: freexl==1.0.5=hd288d7e_1002",
"gdal found but mismatch. Specification pkg: gdal==3.0.2=py37hdf43c64_0, Running pkg: gdal==3.1.2=py37h6ddc196_1",
"geopandas not found",
"geos found but mismatch. Specification pkg: geos==3.8.0=h33f27b4_0, Running pkg: geos==3.8.1=he025d50_0",
"geotiff found but mismatch. Specification pkg: geotiff==1.5.1=h5770a2b_1, Running pkg: geotiff==1.6.0=h09e6dc1_1",
"h5py not found",
"hdf4 found but mismatch. Specification pkg: hdf4==4.2.13=h712560f_2, Running pkg: hdf4==4.2.13=hf8e6fe8_1003",
"hdf5 found but mismatch. Specification pkg: hdf5==1.10.4=h7ebc959_0, Running pkg: hdf5==1.10.6=nompi_he0bbb20_101",
...
]
【讨论】:
以上是关于比较两个 anaconda 安装之间的包的主要内容,如果未能解决你的问题,请参考以下文章