Python中包如何发布?[python高级]
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 setupsetup(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:UsersSe7eN_HOUDesktopmyModule>python setup.py buildrunning build
running build_py
copying sub_Aa.py -> buildlibsub_A
copying sub_B.py -> buildlibsub_B
C:UsersSe7eN_HOUDesktopmyModule>
构建后目录结构:
./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:UsersSe7eN_HOUDesktopmyModule>python setup.py sdistrunning 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.0sub_A
creating Se7eN_HOU-1.0sub_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.0sub_A
hard linking sub_Aa.py -> Se7eN_HOU-1.0sub_A
hard linking sub_B\__init__.py -> Se7eN_HOU-1.0sub_B
hard linking sub_B.py -> Se7eN_HOU-1.0sub_B
creating dist
Creating tar archive
removing 'Se7eN_HOU-1.0' (and everything under it)
C:UsersSe7eN_HOUDesktopmyModule>
打包后,生成最终发布压缩包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高级] 的全部内容, 来源链接: utcz.com/z/540328.html