【问题标题】:Python, run package with `python3.6 -m somepackge.run`Python,使用“python3.6 -m somepackge.run”运行包
【发布时间】:2018-11-03 10:05:09
【问题描述】:

我想对python3.6 -m http.server 做同样的事情。我想像那样运行我的oneliner。我该怎么做呢?现在我有:

def run():
    print('Great!')


if __name__ == '__main__':
    run()

我试过python3.6 -m fastapi,我得到了/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6: No module named test.__main__; 'test' is a package and cannot be directly executed,

和python3.6 -m fastapi.run/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6: No module named test.run

【问题讨论】:

    标签: python python-3.x pip


    【解决方案1】:

    您需要在模块中定义一个名为__main__.py 的魔术文件。请参阅Python 3 docs on __main__。

    您通常在其中运行一个 main() 入口点函数。

    例如,查看pip's 或Tox's one。

    【讨论】:

      猜你喜欢
      • 2019-12-06
      • 2014-01-21
      • 2018-07-18
      • 2020-02-22
      • 2012-03-05
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 2018-02-26
      相关资源
      最近更新 更多