本文共 2170 字,大约阅读时间需要 7 分钟。
目录
http://docs.python.org/3/install/index.html
http://docs.python.org/3/distutils/index.html
创建 setup.py 如下:
# cat setup.pyfrom distutils.core import setupsetup ( name = 'firewall', version = '1.0.0', py_modules = ['firewall'], author = 'neo.chen', author_email = 'netkiller@msn.com', description = 'Module firewall', url='http://netkiller.github.io/',)
注意:name和py_modules这两个参数一定要与firewall.py文件名相同,否则发布安装时会发出模块文件找不到的错误.
打包操作
# python setup.py sdistrunning sdistwarning: sdist: missing required meta-data: urlwarning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)warning: sdist: standard file not found: should have one of README, README.txtwriting manifest file 'MANIFEST'creating firewall-1.0.0making hard links in firewall-1.0.0...hard linking firewall.py -> firewall-1.0.0hard linking setup.py -> firewall-1.0.0creating disttar -cf dist/firewall-1.0.0.tar firewall-1.0.0gzip -f9 dist/firewall-1.0.0.tartar -cf dist/firewall-1.0.0.tar firewall-1.0.0gzip -f9 dist/firewall-1.0.0.tarremoving 'firewall-1.0.0' (and everything under it)
sdist 生成的文件
# ll dist/total 4-rw-r--r--. 1 root root 2123 Aug 9 12:41 firewall-1.0.0.tar.gz
安装包
# python setup.py installrunning installrunning buildrunning build_pycreating buildcreating build/libcopying firewall.py -> build/librunning install_libcopying build/lib/firewall.py -> /usr/lib/python2.6/site-packagesbyte-compiling /usr/lib/python2.6/site-packages/firewall.py to firewall.pycrunning install_egg_infoWriting /usr/lib/python2.6/site-packages/firewall-1.0.0-py2.6.egg-info
安装后
# ll /usr/lib/python2.6/site-packages/firewall*-rw-r--r--. 1 root root 201 Aug 9 12:42 /usr/lib/python2.6/site-packages/firewall-1.0.0-py2.6.egg-info-rw-r--r--. 1 root root 6145 Aug 9 11:28 /usr/lib/python2.6/site-packages/firewall.py-rw-r--r--. 1 root root 11858 Aug 9 12:42 /usr/lib/python2.6/site-packages/firewall.pyc