question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Troubleshooting pkg_resources.DistributionNotFound

See original GitHub issue

Why does this simple program result in a pkg_resources.DistributionNotFound error when run and how do we fix it?

#setup.py
from setuptools import setup

setup(name='my_project',
    version='0.1.0',
    packages=['my_project'],
    entry_points={
        'console_scripts': [
            'my_project = my_project.__main__:main'
        ]
     },
)

.

##my_project/__main__.py

import sys

def main(args=None):
     print("Do Something")

if __name__ == "__main__":
    main()

Build: python setup.py install --root=target --prefix=usr
Run: .\target\usr\Scripts\my_project.exe

Result

Traceback (most recent call last):
  File "D:\code-maphew\scraps\bug-dist-not-found\target\usr\Scripts\my_project-script.py", line 6, in <module>
    from pkg_resources import load_entry_point
  File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 3105, in <module>
    @_call_aside
  File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 3089, in _call_aside
    f(*args, **kwargs)
  File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 3118, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 578, in _build_master
    ws.require(__requires__)
  File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 895, in require
    needed = self.resolve(parse_requirements(requirements))
  File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 781, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'my-project==0.1.0' distribution was not found and is required by the application

This Q is similar to https://stackoverflow.com/questions/35457144/pkg-resources-distributionnotfound-when-using-a-module-installed-from-a-bdist-rp, but not building an RPM. In that Q using --prefix solved the problem. That hasn’t worked for me. I’ve replicated the same problem on Windows 10, Linux Mint, and Debian.

Full code in a repo here: https://github.com/maphew/scraps/tree/master/bug-dist-not-found

Initially posted to Stack Overflow where it has fetched some interest but no answers as yet: https://stackoverflow.com/questions/52375693/troubleshooting-pkg-resources-distributionnotfound-error

Thanks in advance for your time.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
benoit-pierrecommented, Sep 19, 2018

I also agree with the bug reporter that there seem to be a lot of unnecessary runtime dependencies: twine, wheel, keyring, semantic_version, …

Maybe a misguided attempt at working around setup_requires limitations? In which case I suggest looking into PEP 518.

1reaction
benoit-pierrecommented, Sep 19, 2018

You need to set PYTHONPATH, not PYTHONHOME (the later is for changing the location of system files for the interpreter)!

After looking at the issue you linked, and trying locally, the problem seem to be the [bdist_wininst] block in setup.cfg: after removing the block, the install complete successfully (including the scripts), and I can run the code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting pkg_resources.DistributionNotFound error
pkg_resources.DistributionNotFound: The 'req.lib' distribution was not found and is required by the application. Importing was not a problem ...
Read more >
Q: I'm getting DistributionNotFound and entry_point errors ...
Q: I'm getting DistributionNotFound and entry_point errors when I try to run ... If you can run pip install -U setuptools , it...
Read more >
The 'rospkg==1.2.3' distribution was not found and is required ...
My problem is pkg_resources.DistributionNotFound: The 'rospkg>=1.2.7' distribution was not found and is required by rosdep , solved with pip ...
Read more >
Registering a system to Red Hat Insights fails with error ...
Registering a system to Red Hat Insights fails with error pkg_resources.DistributionNotFound: urllib3>=1.21.1,<1.23.
Read more >
pkg_resources.DistributionNotFound: pygmt
I converted my pygmt code into executable file using pyinstaller. I get this error when I run the executable. pkg_resources.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found