# Buggy code
def do_download_dependencies(dev=False, only=False, bare=False):
    """ "Executes the download functionality."""

    # Load the Lockfile.
    lockfile = split_vcs(project._lockfile)

    if not bare:
        click.echo(crayons.yellow("Downloading dependencies from Pipfile..."))

    # Install default dependencies, always.
    deps = lockfile["default"] if not only else {}

    # Add development deps if --dev was passed.
    if dev:
        deps.update(lockfile["develop"])

    # Convert the deps to pip-compatible arguments.
    deps = convert_deps_to_pip(deps, r=False)

    # Actually install each dependency into the virtualenv.
    name_map = {}
    for package_name in deps:
        if not bare:
            click.echo("Downloading {0}...".format(crayons.green(package_name)))

        # pip install:
        c = pip_download(package_name)

        if not bare:
            click.echo(crayons.blue(c.out))

        parsed_output = parse_install_output(c.out)
        for filename, name in parsed_output:
            name_map[filename] = name

    return name_map


# Traceback (KeyError)
➜  testpipenv pipenv install foursquare
Creating a Pipfile for this project...
Creating a virtualenv for this project...
⠋Running virtualenv with interpreter /home/singleton/.pyenv/versions/3.5.2/bin/python
Using base prefix '/home/singleton/.pyenv/versions/3.5.2'
New python executable in /home/singleton/Projects/testpipenv/.venv/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /home/singleton/Projects/testpipenv/.venv
Installing foursquare...
Collecting foursquare
Requirement already satisfied: six in ./.venv/lib/python3.5/site-packages (from foursquare)
Collecting requests>=2.1 (from foursquare)
Using cached requests-2.13.0-py2.py3-none-any.whl
Installing collected packages: requests, foursquare
Successfully installed foursquare-1!2016.9.12 requests-2.13.0

Adding foursquare to Pipfile's [packages]...
➜  testpipenv ls
Pipfile
➜  testpipenv vim Pipfile
➜  testpipenv pipenv lock
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Traceback (most recent call last):
File "/usr/local/bin/pipenv", line 11, in <module>
load_entry_point('pipenv==3.3.6', 'console_scripts', 'pipenv')()
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pipenv/cli.py", line 867, in lock
do_lock()
File "/usr/local/lib/python3.5/dist-packages/pipenv/cli.py", line 431, in do_lock
results = get_downloads_info(names_map, 'packages')
File "/usr/local/lib/python3.5/dist-packages/pipenv/cli.py", line 375, in get_downloads_info
name = list(convert_deps_from_pip(names_map[fname]))[0]
KeyError: 'foursquare-1!2016.9.12.tar.gz'
➜  testpipenv

# Fixed code
def do_download_dependencies(dev=False, only=False, bare=False):
    """ "Executes the download functionality."""

    # Load the Lockfile.
    lockfile = split_vcs(project._lockfile)

    if not bare:
        click.echo(crayons.yellow("Downloading dependencies from Pipfile..."))

    # Install default dependencies, always.
    deps = lockfile["default"] if not only else {}

    # Add development deps if --dev was passed.
    if dev:
        deps.update(lockfile["develop"])

    # Convert the deps to pip-compatible arguments.
    deps = convert_deps_to_pip(deps, r=False)

    # Certain Windows/Python combinations return lower-cased file names
    # to console output, despite downloading the properly cased file.
    # We'll use Requests' CaseInsensitiveDict to address this.
    names_map = requests.structures.CaseInsensitiveDict()

    # Actually install each dependency into the virtualenv.
    for package_name in deps:
        if not bare:
            click.echo("Downloading {0}...".format(crayons.green(package_name)))

        # pip install:
        c = pip_download(package_name)

        if not bare:
            click.echo(crayons.blue(c.out))

        parsed_output = parse_install_output(c.out)
        for filename, name in parsed_output:
            names_map[filename] = name

    return names_map