python文件如何形成安装包?
发布时间:2026-01-20 21:39:48

制作python文件作为安装包的方法:
1、在项目录下创建setupp.py文件, 目录和内容如下
~/vomm$tree . ├──LICENSE ├──MANIFEST ├──MANIFEST.in ├──README.md ├──setup.py ├──vomm │├──classes.py │├──__init__.py │└──tests │├──__init__.py │└──test_vomm.py vimsetup.py """ 两种方式介绍setupp. 从setuptols包,从distutils包.core包,前者可以方便地上传到PyPI发布. 将setup从setuptols包引入setup,同时引入find_packages包搜索项目中的每个packages """ fromsetuptoolsimportsetup,find_packages setup( name='vomm', version=0.1, packages=find_packages(), author='HongheWu', author_email='leopardsaga@gmail.com', url='', license='http://www.apache.org/licenses/LICENSE-2.0.html', description='VariableOrderMarkovModel' )
2、添加MANIFEST.in, 至少包含README说明文件
$catMANIFEST.in includeREADME.md
3、setup.py编译命令
pythonsetup.pybdist_egg#生成类似于bee-0.0的0.0.1-py2.7.egg,支持easy__支持easy__install pythonsetup.pysdist#生成类似于bee-0.0的0.0.1.tar.gz,支持pip pythonsetup.pybuild#编译 pythonsetup.pybdist_wininst#Windowsexe pythonsetup.pybdist_rpm#rpm
4、Python 制作gz压缩包
前2步同上
最后一步是python setup.py sdist, 生成 tar.gz 文件
请关注Python自学网了解更多Python知识。
下一篇 python序列列表怎么排序?
