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文件
fromdistutils.coreimportsetup setup(name="Se7eN_HOU",version="1.0",description="Se7eN_HOU'smodule",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>pythonsetup.pybuild runningbuild runningbuild_py copyingsub_A\a.py->build\lib\sub_A copyingsub_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>pythonsetup.pysdist runningsdist runningcheck warning:check:missingrequiredmeta-data:url warning:check:missingmeta-data:if'author'supplied,'author_email'mustbesuppliedtoo warning:sdist:manifesttemplate'MANIFEST.in'doesnotexist(usingdefaultfilelist) warning:sdist:standardfilenotfound:shouldhaveoneofREADME,README.txt,README.rst writingmanifestfile'MANIFEST' creatingSe7eN_HOU-1.0 creatingSe7eN_HOU-1.0\sub_A creatingSe7eN_HOU-1.0\sub_B makinghardlinksinSe7eN_HOU-1.0... hardlinkingsetup.py->Se7eN_HOU-1.0 hardlinkingsub_A\__init__.py->Se7eN_HOU-1.0\sub_A hardlinkingsub_A\a.py->Se7eN_HOU-1.0\sub_A hardlinkingsub_B\__init__.py->Se7eN_HOU-1.0\sub_B hardlinkingsub_B\b.py->Se7eN_HOU-1.0\sub_B creatingdist Creatingtararchive removing'Se7eN_HOU-1.0'(andeverythingunderit) 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
相关推荐: