问题
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 pkg_resources.DistributionNotFound when using a module installed from a bdist_rpm, 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
回答1:
I just had this same issue. The trouble is the code works on one computer but not on another. Also I am using a wheel that I built. Anyway, the solution I found was to upgrade pip and my package. eg
pip install --upgrade pip path/to/my_package
That re-installed both pip and my package, then the entry points were working.
来源:https://stackoverflow.com/questions/52375693/troubleshooting-pkg-resources-distributionnotfound-error