• 技术文章 >Python技术 >Python高级

    Python中包如何发布?

    爱喝马黛茶的安东尼爱喝马黛茶的安东尼2019-06-28 17:49:20原创2478

    Python中包如何发布?

    1.myModule目录结构体如下:

    ./
        setup.py
        __init__.py
        test.py
        sub_A/
            __init__.py
            a.py
        sub_B/
            __init__.py
            b.py

    2.编辑setup.py文件

    py_modules需指明所需包含的py文件

    from distutils.core import setup
    setup(name = "Se7eN_HOU",version = "1.0",description = "Se7eN_HOU's module",author = "Se7eN_HOU",
    py_modules = ["sub_A.a","sub_B.b"])

    相关推荐:《Python视频教程

    3.构建模块

    使用控制台在setup.py文件的同目录下执行python setup.py build

    C:\Users\Se7eN_HOU\Desktop\myModule>python setup.py build
    running build
    running build_py
    copying sub_A\a.py -> build\lib\sub_A
    copying sub_B\b.py -> build\lib\sub_B
    C:\Users\Se7eN_HOU\Desktop\myModule>

    构建后目录结构:

    ./
        setup.py
        __init__.py
        test.py
        sub_A/
            __init__.py
            a.py
        sub_B/
            __init__.py
            b.py
        build/
            lib/
                sub_A/
                    __init__.py
                    a.py
                sub_B/
                    __init__.py
                    b.py

    4.生成发布压缩包

    同目录下执行python setup.py sdist

    C:\Users\Se7eN_HOU\Desktop\myModule>python setup.py sdist
    running sdist
    running check
    warning: check: missing required meta-data: url
    warning: check: missing meta-data: if 'author' supplied, 'author_email' must be supplied too
    warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)
    warning: sdist: standard file not found: should have one of README, README.txt, README.rst
    writing manifest file 'MANIFEST'
    creating Se7eN_HOU-1.0
    creating Se7eN_HOU-1.0\sub_A
    creating Se7eN_HOU-1.0\sub_B
    making hard links in Se7eN_HOU-1.0...
    hard linking setup.py -> Se7eN_HOU-1.0
    hard linking sub_A\__init__.py -> Se7eN_HOU-1.0\sub_A
    hard linking sub_A\a.py -> Se7eN_HOU-1.0\sub_A
    hard linking sub_B\__init__.py -> Se7eN_HOU-1.0\sub_B
    hard linking sub_B\b.py -> Se7eN_HOU-1.0\sub_B
    creating dist
    Creating tar archive
    removing 'Se7eN_HOU-1.0' (and everything under it)
    C:\Users\Se7eN_HOU\Desktop\myModule>

    打包后,生成最终发布压缩包Se7eN_HOU-1.0tar.gz,目录结构

    ./
        setup.py
        __init__.py
        test.py
        sub_A/
            __init__.py
            a.py
        sub_B/
            __init__.py
            b.py
        build/
            lib/
                sub_A/
                    __init__.py
                    a.py
                sub_B/
                    __init__.py
                    b.py
        MANIFEST
        dist/
            Se7eN_HOU-1.0.tar.gz

    相关推荐:

    Python中包如何嵌套

    专题推荐:python 包
    上一篇:Python中包如何嵌套 下一篇:Python深浅拷贝是什么

    相关文章推荐

    • Python中包如何嵌套

    全部评论我要评论

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

  • 取消发布评论
  • 

    Python学习网