gpt4 book ai didi

python - 使用从 bdist_rpm 安装的模块时 pkg_resources.DistributionNotFound

转载 作者:太空宇宙 更新时间:2023-11-03 16:55:25 25 4
gpt4 key购买 nike

我正在尝试创建我构建的 CLI 工具的 rpm。 rpm 正在创建并安装,没有错误。但是,当我尝试使用 CLI 时,出现以下异常:

    Traceback (most recent call last):
File "/usr/local/bin/my_project", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/site-packages/setuptools-20.1.1-py2.7.egg/pkg_resources/__init__.py", line 3141, in <module>
@_call_aside
File "/usr/lib/python2.7/site-packages/setuptools-20.1.1-py2.7.egg/pkg_resources/__init__.py", line 3127, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/setuptools-20.1.1-py2.7.egg/pkg_resources/__init__.py", line 3154, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python2.7/site-packages/setuptools-20.1.1-py2.7.egg/pkg_resources/__init__.py", line 640, in _build_master
ws.require(__requires__)
File "/usr/lib/python2.7/site-packages/setuptools-20.1.1-py2.7.egg/pkg_resources/__init__.py", line 941, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python2.7/site-packages/setuptools-20.1.1-py2.7.egg/pkg_resources/__init__.py", line 828, 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

我尝试使用以下文件创建一个简单的应用程序以使其正常工作,但我仍然遇到相同的异常

project/setup.py

import sys

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

if __name__ == "__main__":
main()

然后project/my_project/__main__.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'
]
},
)

我正在使用命令 python setup.py bdist_rpm

创建 rpm

编辑

原因是 my_project 被安装到 usr/local/lib 而不是/usr/lib。如何更改默认路径?

最佳答案

我最终只是使用 --install-script 标志指定了一个自定义安装脚本,该标志使用 setup.py install 的前缀选项

安装脚本的内容: python setup.py install --single-version-externally-managed -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES --prefix /usr

关于python - 使用从 bdist_rpm 安装的模块时 pkg_resources.DistributionNotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35457144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com