'Pipenv error when trying to uninstall dependencies

I am quite new to Python and I am trying to setup a project with pipenv. It seemed to work well, but when I tried to uninstall dependencies, I got the following error:

  # pipenv uninstall flask
Uninstalling flask...
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/cli/command.py", line 247, in uninstall
    retcode = do_uninstall(
  File "/usr/local/lib/python3.10/dist-packages/pipenv/core.py", line 2258, in do_uninstall
    with project.environment.activated():
  File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/environment.py", line 894, in activated
    if extra_dist not in self.get_working_set():
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 629, in __contains__
    return self.by_key.get(dist.key) == dist
AttributeError: 'NoneType' object has no attribute 'key'

I uninstalled and installed pipenv, but the issue persists. I am using WSL2.

I also tried uninstalling all dependencies. It have worked, but they did not disappear from the Pipfile - I am not sure if it is a separate issue, but thought it's worth mentioning.

Could someone advise? Also let me know if I missed something.

Thanks!



Solution 1:[1]

Try to remove the virtualenv, that pipenv creates, and after that run again pipenv install, don't forgot to remove flask from pipfile and pipfile.lock

You can try too to execute WSL with admin privileges before.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tlaloc-ES