【问题标题】:Run a python module from an installed package从已安装的包中运行 python 模块
【发布时间】:2020-09-16 21:44:30
【问题描述】:

我有以下示例 python 应用程序:

- testapp
-- __init__.py
-- main.py
-- hello
---- __init.py
---- hello.py
-- world
---- __init__.py
---- world.py

ma​​in.py

from testapp.hello import hello
from testapp.world import world

if __name__ == "__main__":
    hello.say()
    world.say()

world.py

def say():
    print('world')

hello.py

def say():
    print('hello')

然后,我可以进入 testapp 文件夹并运行 python -m main 我得到了'Hello world'的打印

很好,但我想做的是用它构建一个包并将包安装到其他地方以执行它。 我正在使用诗歌来构建whl 包。 我的问题是,如何将软件包安装在其他地方(即在服务器上)并运行它? 我想设置一个分发流程,在其中构建包并将其存储在私有 pypi 存储库中,服务器可以更新和运行整个应用程序。

我尝试在服务器上的文件夹中添加诗歌,它正在工作,因为现在安装了包,但我不知道如何启动包内的主模块。

【问题讨论】:

    标签: python python-packaging python-poetry


    【解决方案1】:

    其实超级简单.. 安装包后,

    python -m testapp.main

    就是这样

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-28
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-08
      • 1970-01-01
      相关资源
      最近更新 更多