【问题标题】:Python setuptools using 'scripts' keyword in setup.py在 setup.py 中使用“scripts”关键字的 Python setuptools
【发布时间】:2017-12-20 05:03:15
【问题描述】:

我正在尝试使用 setuptools 了解 python 打包的工作原理。

setup() 函数的参数之一是 scripts 。 该文档没有指定该参数的用途。任何帮助都会很棒! 下面是一些使用 scripts 的示例代码。

from setuptools import setup, find_packages
setup(
    name="HelloWorld",
    version="0.1",
    packages=find_packages(),
    scripts=['say_hello.py'],

    # Project uses reStructuredText, so ensure that the docutils get
    # installed or upgraded on the target machine
    install_requires=['docutils>=0.3'],

    package_data={
        # If any package contains *.txt or *.rst files, include them:
        '': ['*.txt', '*.rst'],
        # And include any *.msg files found in the 'hello' package, too:
        'hello': ['*.msg'],
    },

    # metadata for upload to PyPI
    author="Me",
    author_email="me@example.com",
    description="This is an Example Package",
    license="PSF",
    keywords="hello world example examples",
    url="http://example.com/HelloWorld/",   # project home page, if any

    # could also include long_description, download_url, classifiers, etc.
)

【问题讨论】:

    标签: python python-2.7 setuptools


    【解决方案1】:

    它主要用于定义您将在包中使用的附加脚本。这是参考链接中的一个 sn-p:

    #!/usr/bin/env python
    import funniest print funniest.joke() 
    

    然后我们可以像这样在 setup() 中声明脚本:

    setup(
        ...
        scripts=['bin/funniest-joke'],
        ... 
        ) 
    

    当我们安装软件包时,setuptools 会将脚本复制到我们的 PATH 并使其可供一般使用。 这具有可推广到的优点 非 python 脚本,以及:最有趣的笑话可能是一个 shell 脚本,或者 完全不同的东西。

    参考:http://python-packaging.readthedocs.io/en/latest/command-line-scripts.html#the-scripts-keyword-argument

    【讨论】:

    • 重要的是要强调scripts 关键字在Windows 中不起作用!如果没有具体原因,请使用第二个选项console_scriptssetuptools entry-point,参考链接中描述,官方“祝福”:packaging.python.org/guides/…
    • 入口点通知:The functions you specify are called with no arguments, and their return value is passed to sys.exit() ...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 2015-08-11
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多