# Buggy code
def get_actions_for_dists(
    dists_for_prefix, only_names, index, force, always_copy, prune, update_deps, pinned
):
    root_only = ("conda", "conda-env")
    prefix = dists_for_prefix.prefix
    dists = dists_for_prefix.specs
    r = dists_for_prefix.r
    specs = [MatchSpec(dist) for dist in dists]
    specs = augment_specs(prefix, specs, pinned)

    linked = linked_data(prefix)
    must_have = odict()

    installed = linked
    if prune:
        installed = []
    pkgs = r.install(specs, installed, update_deps=update_deps)

    for fn in pkgs:
        dist = Dist(fn)
        name = r.package_name(dist)
        if not name or only_names and name not in only_names:
            continue
        must_have[name] = dist

    if is_root_prefix(prefix):
        # for name in foreign:
        #     if name in must_have:
        #         del must_have[name]
        pass
    elif basename(prefix).startswith("_"):
        # anything (including conda) can be installed into environments
        # starting with '_', mainly to allow conda-build to build conda
        pass

    elif any(s in must_have for s in root_only):
        # the solver scheduled an install of conda, but it wasn't in the
        # specs, so it must have been a dependency.
        specs = [s for s in specs if r.depends_on(s, root_only)]
        if specs:
            raise InstallError(
                """\
Error: the following specs depend on 'conda' and can only be installed
into the root environment: %s"""
                % (" ".join(spec.name for spec in specs),)
            )
        linked = [r.package_name(s) for s in linked]
        linked = [s for s in linked if r.depends_on(s, root_only)]
        if linked:
            raise InstallError(
                """\
Error: one or more of the packages already installed depend on 'conda'
and should only be installed in the root environment: %s
These packages need to be removed before conda can proceed."""
                % (" ".join(linked),)
            )
        raise InstallError(
            "Error: 'conda' can only be installed into the root environment"
        )

    smh = r.dependency_sort(must_have)
    actions = ensure_linked_actions(
        smh, prefix, index=r.index, force=force, always_copy=always_copy
    )

    if actions[LINK]:
        actions[SYMLINK_CONDA] = [context.root_prefix]

    for dist in sorted(linked):
        dist = Dist(dist)
        name = r.package_name(dist)
        replace_existing = name in must_have and dist != must_have[name]
        prune_it = prune and dist not in smh
        if replace_existing or prune_it:
            add_unlink(actions, dist)

    return actions


# Traceback (KeyError)
$ conda info -a
Current conda install:

platform : linux-64
conda version : 4.3.13
conda is private : False
conda-env version : 4.3.13
conda-build version : 2.0.2
python version : 2.7.12.final.0
requests version : 2.13.0
root environment : /home/hp/bin/anaconda2  (writable)
default environment : /home/hp/bin/anaconda2/envs/kapsel
envs directories : /home/hp/bin/anaconda2/envs
/home/hp/.conda/envs
package cache : /home/hp/bin/anaconda2/pkgs
/home/hp/.conda/pkgs
channel URLs : https://repo.continuum.io/pkgs/free/linux-64
https://repo.continuum.io/pkgs/free/noarch
https://repo.continuum.io/pkgs/r/linux-64
https://repo.continuum.io/pkgs/r/noarch
https://repo.continuum.io/pkgs/pro/linux-64
https://repo.continuum.io/pkgs/pro/noarch
https://conda.anaconda.org/t/<TOKEN>/binstar/linux-64
https://conda.anaconda.org/t/<TOKEN>/binstar/noarch
config file : /home/hp/.condarc
offline mode : False
user-agent : conda/4.3.13 requests/2.13.0 CPython/2.7.12 Linux/4.9.12-100.fc24.x86_64 Fedora/24 glibc/2.23
UID:GID : 1000:1000

# conda environments:
#
anaconda-platform        /home/hp/bin/anaconda2/envs/anaconda-platform
kapsel                *  /home/hp/bin/anaconda2/envs/kapsel
kapsel-canary            /home/hp/bin/anaconda2/envs/kapsel-canary
py2                      /home/hp/bin/anaconda2/envs/py2
testing                  /home/hp/bin/anaconda2/envs/testing
root                     /home/hp/bin/anaconda2

sys.version: 2.7.12 |Anaconda 4.2.0 (64-bit)| (defaul...
sys.prefix: /home/hp/bin/anaconda2
sys.executable: /home/hp/bin/anaconda2/bin/python
conda location: /home/hp/bin/anaconda2/lib/python2.7/site-packages/conda
conda-build: /home/hp/bin/anaconda2/bin/conda-build
conda-convert: /home/hp/bin/anaconda2/bin/conda-convert
conda-develop: /home/hp/bin/anaconda2/bin/conda-develop
conda-env: /home/hp/bin/anaconda2/bin/conda-env
conda-index: /home/hp/bin/anaconda2/bin/conda-index
conda-inspect: /home/hp/bin/anaconda2/bin/conda-inspect
conda-kapsel: /home/hp/bin/anaconda2/envs/kapsel/bin/conda-kapsel
conda-metapackage: /home/hp/bin/anaconda2/bin/conda-metapackage
conda-render: /home/hp/bin/anaconda2/bin/conda-render
conda-server: /home/hp/bin/anaconda2/envs/kapsel/bin/conda-server
conda-sign: /home/hp/bin/anaconda2/bin/conda-sign
conda-skeleton: /home/hp/bin/anaconda2/bin/conda-skeleton
user site dirs:

CIO_TEST: <not set>
CONDA_DEFAULT_ENV: kapsel
CONDA_ENVS_PATH: <not set>
LD_LIBRARY_PATH: <not set>
PATH: /home/hp/bin/anaconda2/envs/kapsel/bin:/home/hp/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin
PYTHONHOME: <not set>
PYTHONPATH: <not set>

License directories:
/home/hp/.continuum
/home/hp/bin/anaconda2/licenses
License files (license*.txt):
/home/hp/.continuum/license_anaconda_repo_20161003210957.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160804160500.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160727174434.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160728092403.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160830123618.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160803091557.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160830104354.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo.txt
Reading license file : 6
Signature valid : 6
Vendor match : 3
product : u'mkl-optimizations'
packages : u'mkl'
end_date : u'2017-05-24'
type : u'Trial'
product : u'iopro'
packages : u'iopro'
end_date : u'2017-05-24'
type : u'Trial'
product : u'accelerate'
packages : u'numbapro mkl'
end_date : u'2017-05-24'
type : u'Trial'
/home/hp/.continuum/license_anaconda_repo_20160823133054.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160927143648.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160803113033.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160728095857.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160728094900.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160830104619.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160728093131.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20161003210908.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160728094321.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
Package/feature end dates:
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



`$ /home/hp/bin/anaconda2/envs/kapsel/bin/conda info -a`




Traceback (most recent call last):
File "/home/hp/bin/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 591, in conda_exception_handler
return_value = func(*args, **kwargs)
File "/home/hp/bin/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 134, in _main
exit_code = args.func(args, p)
File "/home/hp/bin/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 324, in execute
show_info()
File "_license.pyx", line 363, in _license.show_info (_license.c:10610)
File "_license.pyx", line 310, in _license.get_end_dates (_license.c:9015)
File "_license.pyx", line 166, in _license.filter_vendor (_license.c:6214)
KeyError: 'vendor'

$ conda --version
conda 4.3.13

# Fixed code
def get_actions_for_dists(
    specs_by_prefix, only_names, index, force, always_copy, prune, update_deps, pinned
):
    root_only = ("conda", "conda-env")
    prefix = specs_by_prefix.prefix
    r = specs_by_prefix.r
    specs = [MatchSpec(s) for s in specs_by_prefix.specs]
    specs = augment_specs(prefix, specs, pinned)

    linked = linked_data(prefix)
    must_have = odict()

    installed = linked
    if prune:
        installed = []
    pkgs = r.install(specs, installed, update_deps=update_deps)

    for fn in pkgs:
        dist = Dist(fn)
        name = r.package_name(dist)
        if not name or only_names and name not in only_names:
            continue
        must_have[name] = dist

    if is_root_prefix(prefix):
        # for name in foreign:
        #     if name in must_have:
        #         del must_have[name]
        pass
    elif basename(prefix).startswith("_"):
        # anything (including conda) can be installed into environments
        # starting with '_', mainly to allow conda-build to build conda
        pass

    elif any(s in must_have for s in root_only):
        # the solver scheduled an install of conda, but it wasn't in the
        # specs, so it must have been a dependency.
        specs = [s for s in specs if r.depends_on(s, root_only)]
        if specs:
            raise InstallError(
                """\
Error: the following specs depend on 'conda' and can only be installed
into the root environment: %s"""
                % (" ".join(spec.name for spec in specs),)
            )
        linked = [r.package_name(s) for s in linked]
        linked = [s for s in linked if r.depends_on(s, root_only)]
        if linked:
            raise InstallError(
                """\
Error: one or more of the packages already installed depend on 'conda'
and should only be installed in the root environment: %s
These packages need to be removed before conda can proceed."""
                % (" ".join(linked),)
            )
        raise InstallError(
            "Error: 'conda' can only be installed into the root environment"
        )

    smh = r.dependency_sort(must_have)
    actions = ensure_linked_actions(
        smh, prefix, index=r.index, force=force, always_copy=always_copy
    )

    if actions[LINK]:
        actions[SYMLINK_CONDA] = [context.root_prefix]

    for dist in sorted(linked):
        dist = Dist(dist)
        name = r.package_name(dist)
        replace_existing = name in must_have and dist != must_have[name]
        prune_it = prune and dist not in smh
        if replace_existing or prune_it:
            add_unlink(actions, dist)

    return actions