Troubleshooting pkg_resources.DistributionNotFound
See original GitHub issueWhy 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:
- Created 5 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
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.You need to set
PYTHONPATH
, notPYTHONHOME
(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 insetup.cfg
: after removing the block, the install complete successfully (including the scripts), and I can run the code.