最近寫了一些工具,想到分享給同事時好麻煩,而且本身每次用也是須要打開pycharm這些工具,感受很麻煩,所以想到打包,網上有些例子,照作後又摸索好久方成,索性記錄一下,以備不時之需.python
主要參考:https://blog.csdn.net/llsmingyi/article/details/78691287git
首先寫一個setup.py文件github
# !/usr/bin/env python # -*- coding:utf-8 -*- from setuptools import setup, find_packages setup( name = "setupdemo", version = "0.3", packages = find_packages(), description = "egg test demo", long_description = "egg test demo", author = "luhouxiang", author_email = "luhouxiang@hotmail.com", license = "GPL", keywords = ("setupdemo", "egg"), platforms = "Independant", url = "http://blog.csdn.net/hong201/", entry_points = { 'console_scripts': [ 'setupdemo = setupdemo.hello:main' ] } )
而後再寫要打包的文件夾setupdemo, 使得setupdemo與setup.py在同一目錄層級上工具
在setupdemo中新建一文件hello.py, 代碼以下:url
# !/usr/bin/env python # -*- coding:utf-8 -*- def main(): print('hello') if __name__ == '__main__': main()
再新建一個空文件__init__.pyspa
總體的目錄結構:.net
setupdemo命令行
|_________ setupdemocode
|___________ hello.pyorm
|___________ __init__.py
|_________ setup.py
以上爲最簡單的一個setup.py打包示例, 假設你的工程在e:/work/python/setupdemo, 則打開命令行到setupdemo目錄:
cd /d e:/work/python/setupdemo
而後運行命令:
python setup.py install
看到Finished processing的字樣,說明包已經打好
而後運行已經打好包的文件setupdemo, 不出意外,會顯示hello
示例代碼: https://github.com/luhouxiang/setupdemo