invl / pip-autoremove

Remove a package and its unused dependencies.
Other
620 stars 42 forks source link

Got an pkg_resources.DistributionNotFound error #10

Open nicksspirit opened 6 years ago

nicksspirit commented 6 years ago

I installed pip-autoremove in my python 2.7 environment and as I was trying to pip-autoremove flake8 I got this traceback error:

Traceback (most recent call last): File "/usr/local/bin/pip-autoremove", line 11, in <module> sys.exit(main()) File "/Library/Python/2.7/site-packages/pip_autoremove.py", line 109, in main autoremove(args, yes=opts.yes) File "/Library/Python/2.7/site-packages/pip_autoremove.py", line 21, in autoremove dead = list_dead(names) File "/Library/Python/2.7/site-packages/pip_autoremove.py", line 29, in list_dead graph = get_graph() File "/Library/Python/2.7/site-packages/pip_autoremove.py", line 92, in get_graph for req in requires(dist): File "/Library/Python/2.7/site-packages/pip_autoremove.py", line 98, in requires return map(get_distribution, dist.requires()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 558, in get_distribution dist = get_provider(dist) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 438, in get_provider return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0] File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 959, in require needed = self.resolve(parse_requirements(requirements)) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 846, in resolve raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'tornado' distribution was not found and is required by the application

jorgeorpinel commented 6 years ago

Yes, I get this too... Not working! (Mac OS 10.13.3 with stock Python 2.7.10)

$ pip install --user pip-autoremove
Collecting pip-autoremove
  Using cached pip_autoremove-0.9.0-py2.py3-none-any.whl
Installing collected packages: pip-autoremove
Successfully installed pip-autoremove-0.9.0

$ pip show pip-autoremove
Name: pip-autoremove
Version: 0.9.0
Summary: Remove a package and its unused dependencies
Home-page: https://github.com/invl/pip-autoremove
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache License 2.0
Location: /Users/drbidibombom/Library/Python/2.7/lib/python/site-packages
Requires: 

$ pip-autoremove -l
Traceback (most recent call last):
  File "/Users/drbidibombom/Library/Python/2.7/bin/pip-autoremove", line 11, in <module>
    sys.exit(main())
  File "/Users/drbidibombom/Library/Python/2.7/lib/python/site-packages/pip_autoremove.py", line 107, in main
    list_dead(args)
  File "/Users/drbidibombom/Library/Python/2.7/lib/python/site-packages/pip_autoremove.py", line 29, in list_dead
    graph = get_graph()
  File "/Users/drbidibombom/Library/Python/2.7/lib/python/site-packages/pip_autoremove.py", line 92, in get_graph
    for req in requires(dist):
  File "/Users/drbidibombom/Library/Python/2.7/lib/python/site-packages/pip_autoremove.py", line 98, in requires
    return map(get_distribution, dist.requires())
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 564, in get_distribution
    dist = get_provider(dist)
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 436, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 984, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 870, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'tornado' distribution was not found and is required by the application

UPDATE

You just need to pip install tornado ! (In my case I used pip install --user tornado.)

jorgeorpinel commented 6 years ago

After using this package to autoremove awscli, I also had pkg_resources.DistributionNotFound errors for jmespath<1.0.0,>=0.7.1 and docutils>=0.10, which I had to install manually for pip-autoremove to run again.

It seems the developers didn't configure the package correctly so pip is not installing or registering it's dependencies. So far we know at least of those 3 (tornado, jmespath, docutils).

nicksspirit commented 6 years ago

So wait you are telling me that I have to install tornado for the pkg_resources.DistributionNotFound error to go away

jaraco commented 5 years ago

pkg_resources is known to do some unfriendly things when it comes to dependency resolution, especially if there are gaps in the dependency tree. Here's the error I encountered when trying to autoremove something, even though pipdeptree indicates that the missing dependency is missing from an unrelated package:

setuptools master $ pip-autoremove lpaste                                                                                                    
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/pip-autoremove", line 10, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip_autoremove.py", line 106, in main
    autoremove(args, yes=opts.yes)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip_autoremove.py", line 21, in autoremove
    dead = list_dead(names)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip_autoremove.py", line 29, in list_dead
    graph = get_graph()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip_autoremove.py", line 89, in get_graph
    for req in requires(dist):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 481, in get_distribution
    dist = get_provider(dist)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 357, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 900, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 786, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'userpath' distribution was not found and is required by the application

Perhaps the best recommendation here would be not to use pkg_resources, but instead use importlib_metadata, which avoids enumerating the whole environment when finding package metadata.

jaraco commented 5 years ago

It seems the developers didn't configure the package correctly.

I don't believe this is the issue. I suspect one can replicate the issue by installing some package (with dependencies), uninstalling one of the dependencies on that package, and then trying to run pip-autoremove.

otavio-silva commented 4 years ago

Did anyone find out a solution for this?

tresni commented 3 years ago

Should be addressed by the merge of #42 and the new release, please close if that resolves your issue.