0

如果我用终端调用它,我想为 python 模块构建一个基于 debian 的 deb 包并得到一个 ModuleNotFoundError。我创建了一个最小的例子。

目录结构:

hello
  - debian
      - control
      - rules
  - hello
      - main.py
  - setup.py

rules

#!/usr/bin/make -f

export DH_VERBOSE=1
export PYBUILD_NAME=hello

%:
        dh $@ --with python3 --buildsystem=pybuild

control

Source: hello
Section: python
Priority: optional
Build-Depends:
  debhelper-compat (= 12),
  dh-python,
  python3-all,
  python3-setuptools,
  python3-click,
  python3-yaml
Standards-Version: 0.1
X-Python3-Version: >= 3.6

Package: hello
Architecture: all
Section: utils
Depends: python3-hello, ${python3:Depends}, ${misc:Depends}
Description: print hello

setup.py

from setuptools import setup

setup(
    name="hello",
    version="0.1",
    author="Me",
    description="Print hello",
    install_requires=[],
    license="MIT",
    python_requires=">=3.6",
    package_dir={"": "hello"},
    package_data={"hello": ["*"]},
    extras_require={},
    entry_points={
        "console_scripts": [
             "hello=hello.main:main",
        ]
    },
)

main.py

#!/usr/bin/env python

import click


@click.command()
@click.version_option()
def main():
     print("Hello")


if __name__ == "__main__":
     main()

然后我运行sudo python3 setup.py --command-packages=stdeb.command bdist_deb并安装 deb 包sudo dpkg -i python3-hello

当我运行时,hello我收到此错误消息:

File "/usr/bin/hello", line 11, in <module>
  load_entry_point('hello==0.1', 'console_scripts', 'hello')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 490, in load_entry_point
  return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2854, in load_entry_point
  return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2445, in load
  return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2451, in resolve
  module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'hello'
4

0 回答 0