python打包工具distutils
参考: http://www.cppcns.com/jiaoben/python/225742.html
python源码包安装:python setup.py install
distutils
distutils 是 python 标准库的一部分,这个库的目的是为开发者提供一种方便的打包方式, 同时为使用者提供方便的安装方式。当我们开发了自己的模块之后,使用distutils的setup.py打包。
hello.py import time print("Current time:",time.asctime()) def hello_fun(): print("This is my function hello")
setup.py from distutils.core import setup setup( name="hello_module", version="1.0", author="", author_email="", py_modules=['hello'], )
执行打包命令 python setup.py sdist
C:\Users\23798\Desktop\desktop\my_note\python_project\mysetuptool>python setup.py sdist running sdist running check warning: check: missing required meta-data: url warning: check: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list) writing manifest file 'MANIFEST' creating hello_module-1.0 copying files to hello_module-1.0... copying README -> hello_module-1.0 copying hello.py -> hello_module-1.0 copying setup.py -> hello_module-1.0 creating dist creating 'dist\hello_module-1.0.zip' and adding 'hello_module-1.0' to it adding 'hello_module-1.0' adding 'hello_module-1.0\hello.py' adding 'hello_module-1.0\PKG-INFO' adding 'hello_module-1.0\README' adding 'hello_module-1.0\setup.py' removing 'hello_module-1.0' (and everything under it)
hello_module-1.0.zip就是生成的python模块, 解压后使用python setup.py install
安装该模块。从路径可以看出,该模块安装到标准库的制定路径下。
C:\Users\23798\Desktop\desktop\my_note\python_project\mysetuptool\dist\hello_module-1.0>python setup.py install running install running build running build_py creating build creating build\lib copying hello.py -> build\lib running install_lib copying build\lib\hello.py -> C:\Python27\Lib\site-packages byte-compiling C:\Python27\Lib\site-packages\hello.py to hello.pyc running install_egg_info Writing C:\Python27\Lib\site-packages\hello_module-1.0-py2.7.egg-info
现在,我们就可以打开python导入这个包了
>>> import hello ('Current time:', 'Tue Nov 22 21:28:18 2022')
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
2019-11-22 mysql数据库E-R图
2019-11-22 python装饰器