简体   繁体   English

运行通过使用 stdeb 创建的 deb 安装的 python 脚本时出现 ModuleNotFoundError

[英]ModuleNotFoundError when running python script installed via deb created using stdeb

I've build a really simple Python project I'm packaging into a.deb file for installation.我已经构建了一个非常简单的 Python 项目,我正在打包到一个 .deb 文件中进行安装。 I've got the building of.deb working, but when I run my script via it's command, I get a ModuleNotFoundError.我已经构建了.deb,但是当我通过它的命令运行我的脚本时,我得到了一个 ModuleNotFoundError。

My project structure is as follows:我的项目结构如下:

setup.py
hello
  |
  | - __init.py__
  | - hello.py
  | - world.py

setup.py安装程序.py

import os
from setuptools import setup, find_packages
setup(
    name = "hello_py",
    version = "1.3",
    author = "Sion Hughes",
    author_email = "",
    description = "It's a simple hello world, but this time with 2 python file",
    license = "",
    url = " ",
    packages=find_packages(),
    entry_points = {
        'console_scripts' : ['hello = hello.hello:main',
        'command-name = hello.hello:main']
    },
    classifiers=[
        "License :: OSI Approved :: BSD License",
    ],
)

hello.py你好.py

#!/usr/bin/env python3
import world

def main():
    print("Hello, this is Siôn's python script")
    world.hello()

if __name__ == "__main__":
    main()

world.py世界.py

#!/usr/bin/env python3

def hello():
    print("Hello from another Python file")

All runs fine locally, but when I run using hello command, I get the following error:一切在本地运行良好,但是当我使用hello命令运行时,出现以下错误:

# hello
Traceback (most recent call last):
  File "/usr/bin/hello", line 11, in <module>
    load_entry_point('hello-py==1.3', '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)
  File "/usr/lib/python3/dist-packages/hello/hello.py", line 5, in <module>
    import world
ModuleNotFoundError: No module named 'world'

Where am I going wrong to get this working?我在哪里错了让这个工作? Thanks in advance.提前致谢。

Update: Forgot to say in the initial post, I want to be able to run the scripts in their local directory for development purposes too, not just always run via installed.deb更新:忘了在最初的帖子中说,我也希望能够在其本地目录中运行脚本以用于开发目的,而不仅仅是通过 installed.deb 运行

Instead of import world in hello.py, try using import.world .不要在 hello.py 中import world ,而是尝试使用import.world

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用python stdeb更新已经创建的包 - using python stdeb to update already created packages 通过stdeb从Python包创建Debian包:什么是.deb文件? - Creating a Debian package from Python package via stdeb: what is .deb file? 在stdeb bdist_deb调用时覆盖或禁用$ {python:Depends} - Overriding or disabling ${python:Depends} at stdeb bdist_deb invocation 在anaconda提示符下运行Python脚本时发生ModuleNotFoundError - ModuleNotFoundError when running Python script in anaconda prompt Atom在运行python脚本时显示ModuleNotFoundError - Atom shows ModuleNotFoundError when running python script Anaconda 提示:运行 Python 脚本时出现 ModuleNotFoundError - Anaconda prompt: ModuleNotFoundError when running Python script 从 `console_scripts` 运行脚本但通过 Python 控制台导入时不会出现 `ModuleNotFoundError` - `ModuleNotFoundError` when running script from `console_scripts` but not when importing via Python console 运行脚本时出现 ModuleNotFoundError 错误 - ModuleNotFoundError error when running script 从批处理文件运行 python 脚本时出现 ModuleNotFoundError - ModuleNotFoundError when running python script from a batch file Vscode 给出“ModuleNotFoundError”,当使用右角箭头运行 python 脚本时 - Vscode gives "ModuleNotFoundError", when running python script with right corner arrow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM