【问题标题】:What's the best way to distribute python command-line tools?分发 python 命令行工具的最佳方式是什么?
【发布时间】:2010-09-06 06:47:42
【问题描述】:

我当前的setup.py 脚本工作正常,但它会将tvnamer.py(工具)作为tvnamer.py 安装到站点包或类似的地方..

我可以让setup.pytvnamer.py 安装为tvnamer,和/或有更好的安装命令行应用程序的方法吗?

【问题讨论】:

标签: python command-line packaging


【解决方案1】:

在 setup() 调用中尝试 entry_points.console_scripts 参数。正如setuptools docs 中所述,这应该可以满足您的需求。

在这里重现:

from setuptools import setup

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

【讨论】:

  • 当我在 Python 2.6 和 3.1 中尝试这个时,我收到了一条消息 UserWarning: Unknown distribution option: 'entry_points'。所以我猜它在 Python(2.6 和 3.1)附带的 distutils 中不受支持。那么,如果我们想在 PyPI 上分发,是否可以使用此选项?
  • 在 Ubuntu 11.04 上,安装 python-setuptools。确保你 setup.py 正在导入:'from setuptools import setup'
猜你喜欢
  • 2010-09-28
  • 2022-06-15
  • 1970-01-01
  • 2011-11-29
  • 2014-12-17
  • 2011-03-05
  • 2021-11-23
  • 2014-03-18
相关资源
最近更新 更多