Pipenv: KeyError when during `pipenv install <package>`

Created on 18 Jan 2018  Â·  10Comments  Â·  Source: pypa/pipenv

Key error when installing dependency. It seams to happen when pipenv is trying to add dependency to Pipfile:

Action:

pipenv install mock

Environment

  1. MacOS 10.12.6 Sierra
  2. Python version: 3.6.4
  3. Pipenv version: 8.3.2
Expected result

No KeyError raised. Dependency added to Pipfile.

Actual result

KeyError raised. Dependency is not added to Pipfile.

Installing mock…
Requirement already satisfied: mock in /Users/robin/.local/share/virtualenvs/ATG-PATKL30Y/lib/python3.6/site-packages
Requirement already satisfied: pbr>=0.11 in /Users/robin/.local/share/virtualenvs/ATG-PATKL30Y/lib/python3.6/site-packages (from mock)
Requirement already satisfied: six>=1.9 in /Users/robin/.local/share/virtualenvs/ATG-PATKL30Y/lib/python3.6/site-packages (from mock)

Adding mock to Pipfile's [packages]…
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/cli.py", line 1923, in install
    project.add_package_to_pipfile(package_name, dev)
  File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 461, in add_package_to_pipfile
    p = self._pipfile
  File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 268, in _pipfile
    p_section[norm_key] = p_section.pop(key)
  File "/usr/local/lib/python3.6/site-packages/pipenv/patched/prettytoml/elements/table.py", line 114, in pop
    v = self[key]
  File "/usr/local/lib/python3.6/site-packages/pipenv/patched/prettytoml/elements/abstracttable.py", line 58, in __getitem__
    raise KeyError
KeyError

Steps to replicate

Use this Pipfile

[[source]]

verify_ssl = true
url = "https://pypi.python.org/simple"


[requires]

python_version = '3.6'


[packages]

xlrd = "==1.1.0"
xlsxwriter = "==0.9.9"
pip-conflict-checker = "==0.3"
mypy = "==0.530"
pylint = "==1.7.4"
hyperopt = "==0.1"
networkx = "==1.11"
pyyaml = "==3.12"
scipy = "==0.18.1"
scikit-learn = "==0.19.1"


[dev-packages]

tensorflow = "==1.4.0"
matplotlib = "==2.1.1"

Then install mock with:
pipenv install mock

Most helpful comment

@monkut It should be gone in master branch.

All 10 comments

Couldn't reproduce this on Ubuntu 17.10 x64, with Python 3.6.3 & Pipenv 9.0.3.

Tried both your steps and following:

  • placed your Pipfile into the working directory
  • pipenv install
  • pipenv install mock

Did you try to update Pipenv to the latest version?

Reproducable with the newest version of pipenv (9.0.3), Python 3.6.4, macOS 10.12.6 Sierra:

Checking version
pipenv --version
pipenv, version 9.0.3
Installing dependency
pipenv install mock

Installing mock…
Requirement already satisfied: mock in /Users/robin/.local/share/virtualenvs/ATG-PATKL30Y/lib/python3.6/site-packages
Requirement already satisfied: six>=1.9 in /Users/robin/.local/share/virtualenvs/ATG-PATKL30Y/lib/python3.6/site-packages (from mock)
Requirement already satisfied: pbr>=0.11 in /Users/robin/.local/share/virtualenvs/ATG-PATKL30Y/lib/python3.6/site-packages (from mock)

Adding mock to Pipfile's [packages]…
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/cli.py", line 1922, in install
    project.add_package_to_pipfile(package_name, dev)
  File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 479, in add_package_to_pipfile
    p = self._pipfile
  File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 286, in _pipfile
    p_section[norm_key] = p_section.pop(key)
  File "/usr/local/lib/python3.6/site-packages/pipenv/patched/prettytoml/elements/table.py", line 114, in pop
    v = self[key]
  File "/usr/local/lib/python3.6/site-packages/pipenv/patched/prettytoml/elements/abstracttable.py", line 58, in __getitem__
    raise KeyError
KeyError

Update. Apparently there was something strange with the formatting of my local Pipfile. Just copy and paste the same Pipfile from here into my editor (which look identical) solved the issue.

I just ran into this (Py 2.7, pipenv 11.0.2)
Removed a #comment from the end of one line in the Pipfile and it started working again.

@funckybob Upgrade Pipenv. I believe I fixed this a while ago.

hmmmm....

Got this strange error when trying to install added django-s3direct = {git = "https://github.com/goya813/django-s3direct.git", editable = true, ref = "feature/multiple-upload"} to my _Pipfile_.

...
  File "/home/yuser/.local/lib/python3.7/site-packages/pipenv/cli/command.py", line 254, in install
    editable_packages=state.installstate.editables,
  File "/home/yuser/.local/lib/python3.7/site-packages/pipenv/core.py", line 1874, in do_install
    keep_outdated=keep_outdated
  File "/home/yuser/.local/lib/python3.7/site-packages/pipenv/core.py", line 1221, in do_init
    pypi_mirror=pypi_mirror,
  File "/home/yuser/.local/lib/python3.7/site-packages/pipenv/core.py", line 1068, in do_lock
    lockfile=lockfile
  File "/home/yuser/.local/lib/python3.7/site-packages/pipenv/utils.py", line 682, in venv_resolve_deps
    lockfile[lockfile_section][k].update(v)
KeyError: 'asgiref'

@monkut It should be gone in master branch.

I'm getting the same error as @monkut when trying to pipenv update --outdated with a Pipfile that hasn't changed since last time I did this. I'm using version 2018.11.26 which appears to be the latest version? If the fix is only on master, will it be released soon? Thanks.

I think it's this line in my Pipfile that's causing the problem:

wagtailcomments-xtd = {editable = true,git = "https://github.com/UnfoldStories/wagtailcomments_xtd.git",ref = "wagtail-2-fixes"}

I've tried installing that package afresh, doing this:

  1. pipenv --rm
  2. rm Pipfile.lock
  3. Comment out the wagtailcomments-xtd... line from Pipfile
  4. pipenv install --dev
  5. pipenv install -e git+https://github.com/UnfoldStories/wagtailcomments_xtd.git@wagtail-2-fixes#egg=wagtailcomments_xtd

The last step results in:

Traceback (most recent call last):
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/bin/pipenv", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/cli/command.py", line 235, in install
    retcode = do_install(
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/core.py", line 1983, in do_install
    do_init(
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/core.py", line 1216, in do_init
    do_lock(
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/core.py", line 1058, in do_lock
    venv_resolve_deps(
  File "/usr/local/Cellar/pipenv/2018.11.26_3/libexec/lib/python3.8/site-packages/pipenv/utils.py", line 682, in venv_resolve_deps
    lockfile[lockfile_section][k].update(v)
KeyError: 'asgiref'

Neither this project nor that wagtailcomments_xtd repo have changed recently and this -- doing pipenv updates -- has been working OK for a few months.

Having a similar issue to the one described above, can confirm that KeyError: 'asgiref' only happens on VCS dependencies with editable=true. I added editable=true to work around the issue where pipenv installed wrong versions in Docker, and now I get the error. Removing the editable parameter fixes that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

randName picture randName  Â·  3Comments

hynek picture hynek  Â·  3Comments

bgjelstrup picture bgjelstrup  Â·  3Comments

konstin picture konstin  Â·  3Comments

xi picture xi  Â·  3Comments