目錄
http://docs.python.org/3/install/index.html
http://docs.python.org/3/distutils/index.html
創建 setup.py 如下:
# cat setup.py from distutils.core import setup setup ( 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 sdist running sdist warning: sdist: missing required meta-data: url 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 writing manifest file 'MANIFEST' creating firewall-1.0.0 making hard links in firewall-1.0.0... hard linking firewall.py -> firewall-1.0.0 hard linking setup.py -> firewall-1.0.0 creating dist tar -cf dist/firewall-1.0.0.tar firewall-1.0.0 gzip -f9 dist/firewall-1.0.0.tar tar -cf dist/firewall-1.0.0.tar firewall-1.0.0 gzip -f9 dist/firewall-1.0.0.tar removing '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 install running install running build running build_py creating build creating build/lib copying firewall.py -> build/lib running install_lib copying build/lib/firewall.py -> /usr/lib/python2.6/site-packages byte-compiling /usr/lib/python2.6/site-packages/firewall.py to firewall.pyc running install_egg_info Writing /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