分发Python命令行工具的最佳方法是什么?

43 投票
1 回答
6835 浏览
提问于 2025-04-11 09:17

我现在的 setup.py 脚本运行得还不错,但它把 tvnamer.py(这个工具)安装成了 tvnamer.py,放在了 site-packages 或者类似的地方。

我能不能让 setup.pytvnamer.py 安装成 tvnamer,或者有没有更好的方法来安装命令行应用程序呢?

1 个回答

38

试试在setup()调用中使用entry_points.console_scripts这个参数。根据setuptools的文档,这个应该能实现你想要的功能。

在这里重现一下:

from setuptools import setup

setup(
    # other arguments here...
    entry_points = {
        'console_scripts': [
            'foo = package.module:func',
            'bar = othermodule:somefunc',
        ],
    }
)

撰写回答