Conda environment: Print licenses of installed packages

Question:

is there an easy way to print the license of each package in a conda environment?

conda list nicely lists all packages, however there is no option to get information about the license. On Anaconda the license is shown.

I tried to find the licenses in each package folder, but was not lucky. Is the only option to look at each package individually on Anaconda.org?

Conda version 4.6.14

Thanks

Asked By: Michael

||

Answers:

You can find it in the JSON files under the conda-meta folder in each env. The key license is in the main object, if you’re looking to parse the JSON. Otherwise, you can get a quick look with:

grep '"license":' conda-meta/*.json

which outputs the following (abridged) for me:

conda-meta/aioeasywebdav-2.4.0-py37_1000.json:  "license": "ISC",
conda-meta/aiohttp-3.5.4-py37h1de35cc_0.json:  "license": "Apache 2.0",
conda-meta/appdirs-1.4.3-py37h28b3542_0.json:  "license": "MIT",
conda-meta/appnope-0.1.0-py37_0.json:  "license": "BSD 2-Clause",
conda-meta/asn1crypto-0.24.0-py37_0.json:  "license": "MIT",
...
conda-meta/xz-5.2.4-h1de35cc_4.json:  "license": "LGPL-2.1 and GPL-2.0",
conda-meta/yaml-0.1.7-hc338f04_2.json:  "license": "MIT",
conda-meta/yarl-1.3.0-py37h1de35cc_0.json:  "license": "Apache 2.0",
conda-meta/zeromq-4.2.5-h0a44026_1.json:  "license": "LGPL 3",
conda-meta/zlib-1.2.11-h1de35cc_3.json:  "license": "zlib",
Answered By: merv

I found pip-licenses not to work in my conda env. Instead, you can get all conda-installed and pip-installed packages and their license info like so:

conda list | awk '{if(NR>3) printf("%s=%sn", $1, $2)}' | xargs conda info | grep 'name|version|license'

which outputs

file name   : argon2-cffi-21.3.0-pyhd3eb1b0_0.conda
name        : argon2-cffi
version     : 21.3.0
license     : MIT
license_family: MIT
file name   : argon2-cffi-bindings-21.2.0-py310h1a28f6b_0.conda
name        : argon2-cffi-bindings
version     : 21.2.0
license     : MIT
license_family: MIT
...
file name   : xz-5.2.5-h1a28f6b_1.conda
name        : xz
version     : 5.2.5
license     : LGPL-2.1-or-later and GPL-2.0-or-later
license_family: GPL2
file name   : zlib-1.2.12-h5a0b063_2.conda
name        : zlib
version     : 1.2.12
license     : Zlib
license_family: Other
file name   : zlib-1.2.12-h5a0b063_3.conda
name        : zlib
version     : 1.2.12
license     : Zlib
license_family: Other
Answered By: user1166202