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"])
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
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试