对 pkg_resources.DistributionNotFound 错误进行故障排除 [英] Troubleshooting pkg_resources.DistributionNotFound error
问题描述
为什么这个简单的程序会导致运行时出现 pkg_resources.DistributionNotFound
错误,我们如何解决?
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()
构建: python setup.py install --root=target --prefix=usr
运行: .\target\usr\Scripts\my_project.exe
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
这个Q类似于pkg_resources.DistributionNotFound 使用从 bdist_rpm 安装的模块,但不构建 RPM 时.在那个 Q 中使用 --prefix
解决了这个问题.那对我没有用.我在 Windows 10、Linux Mint 和 Debian 上复制了同样的问题.
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.
完整代码在此处:https://github.com/maphew/scraps/tree/master/bug-dist-not-found
推荐答案
我刚刚遇到了同样的问题.问题是代码可以在一台计算机上运行,但不能在另一台计算机上运行.我也在使用我制造的轮子.无论如何,我找到的解决方案是升级 pip 和我的包.例如
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
重新安装了 pip 和我的包,然后入口点就可以工作了.
That re-installed both pip and my package, then the entry points were working.
这篇关于对 pkg_resources.DistributionNotFound 错误进行故障排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!