[英]Troubleshooting pkg_resources.DistributionNotFound error
Why doesthis simple program result in a pkg_resources.DistributionNotFound
error when run and how do we fix it?为什么这个简单的程序在运行时会导致
pkg_resources.DistributionNotFound
错误,我们该如何解决?
#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
构建:
python setup.py install --root=target --prefix=usr
Run: .\\target\\usr\\Scripts\\my_project.exe
运行:
.\\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
This Q is similar to pkg_resources.DistributionNotFound when using a module installed from a bdist_rpm , but not building an RPM. 当使用从 bdist_rpm 安装的模块但不构建 RPM 时,此 Q 类似于pkg_resources.DistributionNotFound 。 In that Q using
--prefix
solved the problem.在那个 Q 中使用
--prefix
解决了这个问题。 That hasn't worked for me.那对我没有用。 I've replicated the same problem on Windows 10, Linux Mint, and Debian.
我已经在 Windows 10、Linux Mint 和 Debian 上复制了同样的问题。
Full code in a repo here:https://github.com/maphew/scraps/tree/master/bug-dist-not-found此处存储库中的完整代码:https ://github.com/maphew/scraps/tree/master/bug-dist-not-found
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.
无论如何,我找到的解决方案是升级 pip 和我的包。 eg
例如
pip install --upgrade pip path/to/my_package
That re-installed both pip and my package, then the entry points were working.重新安装了 pip 和我的包,然后入口点就可以工作了。
In case you have similar issue mentioned in the question you also might have a name mismatch like I had:如果您在问题中提到了类似的问题,您也可能会遇到像我这样的名称不匹配:
setup.py设置文件
#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'
]
},
install_requires=[
'req.lib', # correct name req-lib
]
)
Interestingly in my case pip install -e .
有趣的是,在我的情况下
pip install -e .
did not complain about the the error, but I got an error during execution, like the following one:没有抱怨错误,但我在执行过程中遇到错误,如下所示:
pkg_resources.DistributionNotFound: The 'req.lib' distribution was not found and is required by the application
pkg_resources.DistributionNotFound:未找到“req.lib”分发版,应用程序需要此分发版
Importing was not a problem there the naming was correct the following ways:导入不是问题,命名正确的方式如下:
import req.lib
The package in my case was 'azure-identity' :)我的情况下的包裹是“azure-identity”:)
The installation using pip has certainly different tolerance compared to pkg_resources .与pkg_resources相比,使用pip的安装肯定有不同的容忍度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.