• 技术文章 >常见问题 >Python常见问题

    python中setuptools是什么

    yangyang2020-05-11 13:16:24原创4295

    Setuptools是Python Distutils的加强版,可以让程序员更方便的创建和发布 Python 包,特别是那些对其它包具有依赖性的状况。用setuptools构建和发布的包与用Distutils发布的包是类似的。

    包的使用者无需安装setuptools就可以使用该包。如果用户是从源码包开始构建,并且没有安装过setuptools的话,则只要在你的setup脚本中包含一个bootstrap模块(ez_setup),用户构建时就会自动下载并安装setuptools了。

    一:基本用例

    下面是一个使用setuptools的简单例子:

    1

    2

    3

    4

    5

    6

    from setuptools import setup, find_packages

    setup(

        name = "HelloWorld",

        version = "0.1",

        packages = find_packages(),

    )

    上面就是一个最简单的setup脚本,使用该脚本,就可以产生eggs,上传PyPI,自动包含setup.py所在目录中的所有包等。

    当然,上面的脚本过于简单,下面是一个稍微复杂的例子:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    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视频教程栏目。

    专题推荐:python
    上一篇:python中sort是什么意思 下一篇:python中r作用是什么?

    相关文章推荐

    • python怎么判断一个数是几位数• 用python写好的程序如何在别处用• python中如何计算矩阵的行数?• python中如何删除字符串中的空格

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网