Python setuptools 在 setup.py 中使用“scripts”关键字

问题描述 投票:0回答:1

我正在尝试使用 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="[email protected]",
    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个回答
22
投票

它主要用于定义您将在包中使用的附加脚本。以下是有关 python 打包的官方文档的片段:

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

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.