知行编程网知行编程网  2022-10-25 03:30 知行编程网 隐藏边栏  8 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于python中setuptools是什么的相关知识,希望可以帮到处于编程学习途中的小伙伴

python中的setuptools是什么


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

用setuptools构建和发布的包与用Distutils发布的包是类似的。

包的消费者可以在不安装 setuptools 的情况下使用包。如果用户从源码包构建并且没有安装setuptools,只要在安装脚本中包含引导模块(ez_setup),用户在构建时会自动下载并安装setuptools。

一:基本用例

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

from setuptools import setup, find_packages
setup(
    name = "HelloWorld",
    version = "0.1",
    packages = find_packages(),
)

以上是最简单的设置脚本。使用这个脚本,你可以生成egg,上传PyPI,自动包含setup.py所在目录下的所有包。

当然,上面的脚本太简单了,这里再举一个稍微复杂一点的例子:

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

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享