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

2024-06-11 22:09:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图理解python打包是如何使用setuptools工作的。

函数的参数之一是脚本。 文档没有指定该参数的用途。任何帮助都太好了! 下面是一些使用脚本的示例代码。

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.
)

Tags: orthe脚本packagehello参数includeexample
1条回答
网友
1楼 · 发布于 2024-06-11 22:09:38

它主要用于定义将在包中使用的其他脚本。以下是引用链接中的片段:

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

然后我们可以在setup()中声明脚本,如下所示:

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

When we install the package, setuptools will copy the script to our PATH and make it available for general use. This has advantage of being generalizeable to non-python scripts, as well: funniest-joke could be a shell script, or something completely different.

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

相关问题 更多 >