Python: Packaging with Wheel and egg

最后发布时间:2023-06-28 00:25:42 浏览量:

生信小木屋

Wheel和Egg都是python的打包格式,目的是支持不需要编译或制作的安装过程,实际上也是一种压缩文件,将.whl的后缀改为.zip即可可看到压缩包里面的内容。按照官网说法,wheels是发行版Python的新标准并且要取代.egg

distutils

hello.py

def hello_fun():
 print "i say hello to you"

setup.py

from distutils.core import setup
setup(
 name="hello_module",
 version="1.0",
 author="ljk",
 author_email="wilber@sh.com",
 py_modules=['hello'],
)

setuptools

printtest.py

def test():
  print('print test')

setup.py

from setuptools import setup
setup(name='printtest',
   version='1.0', 
   py_modules=['printtest'],
   )
python setup.py sdist
python setup.py bdist_wheel
python setup.py bdist_egg

https://www.cnblogs.com/wuzhiblog/p/python_make_egg_or_whl.html

(base) ➜  01 tree dist 
dist
├── printtest-1.0
│   ├── build
│   │   ├── bdist.linux-x86_64
│   │   └── lib
│   │       └── printtest.py
│   ├── dist
│   │   └── printtest-1.0-py3.8.egg
│   ├── PKG-INFO
│   ├── printtest.egg-info
│   │   ├── dependency_links.txt
│   │   ├── PKG-INFO
│   │   ├── SOURCES.txt
│   │   └── top_level.txt
│   ├── printtest.py
│   ├── __pycache__
│   │   └── printtest.cpython-38.pyc
│   ├── setup.cfg
│   └── setup.py
└── printtest-1.0.tar.gz


python setup.py install

import printtest
printtest.test()

参考

https://www.jb51.net/article/180223.htm
https://www.jb51.net/article/138538.htm