如何为 pip 安装的 python 包启用 shell 命令行参数?

Jos*_*ein 5 python pip pypi

那么对于 python 包,如何从 pip 安装的包启用命令行参数?下面是一个名为 mrbob 的包的示例:

$ pip install mrbob
$ mrbob DoSomethingFunction
Run Code Online (Sandbox Code Playgroud)

如何为 python 包启用命令行选项和新的 shell 命令?

tal*_*nat 3

使用setuptools,定义一个console_script入口点:

setup(
    # other arguments here...
    entry_points={
        'console_scripts': [
            'mrbob = my_package.some_module:main_func',
        ]
    }
)
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅文档中的自动脚本创建。setuptools

distutils, 使用scripts:

setup(...,
      scripts=['scripts/mrbob']
      )
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅文档中的安装脚本。distutils