python Setuptools
来源:互联网 发布:酸奶对人体好吗 知乎 编辑:程序博客网 时间:2024/05/16 19:55
what is setuptools
Setuptools is a fully-featured, actively-maintained, and stable library designed to facilitate packaging Python projects, where packaging includes:
- Python package and module definitions
- Distribution package metadata
- Test hooks
- Project installation
- Platform-specific details
- Python 3 support
install setuptools
- for ubuntu
sudo apt-get install python-setuptools - for package install
wget http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
examples
i will use a simple example to show how setuptools work
- Create new directory
mkdir demo cd demo
- Create setup files
from setuptools import setuppackage = 'name'version = '0.1'setup(name=package, version=version, description="description", url='url')
- variables
- name is package name
- version is package current version
- description is pacckage description
then run python setup.py bdist_egg
to build python-eggs for python test, you will find a eggs file in demo/dist directory. if you look into this eggs file you will find out that it is a zip file
cli:~/demo$ file dist/name-0.1-py2.7.egg dist/name-0.1-py2.7.egg: Zip archive data, at least v2.0 to extractcli:~/demo$ unzip -l dist/name-0.1-py2.7.egg Archive: dist/name-0.1-py2.7.egg Length Date Time Name--------- ---------- ----- ---- 1 2016-10-17 11:17 EGG-INFO/dependency_links.txt 176 2016-10-17 11:17 EGG-INFO/PKG-INFO 120 2016-10-17 11:17 EGG-INFO/SOURCES.txt 1 2016-10-17 11:17 EGG-INFO/zip-safe 1 2016-10-17 11:17 EGG-INFO/top_level.txt--------- ------- 299 5 files
- add some funtion into package
mkdir demo cd demotouch __init__.py
put these code into __init__.py
def test(): print "hello world!" if __name__ == '__main__': test()
and then run python setup.py bdist_eggs
again
cli:~/demo$ unzip -l dist/name-0.1-py2.7.egg Archive: dist/name-0.1-py2.7.egg Length Date Time Name--------- ---------- ----- ---- 1 2016-10-17 11:17 EGG-INFO/dependency_links.txt 176 2016-10-17 11:17 EGG-INFO/PKG-INFO 120 2016-10-17 11:17 EGG-INFO/SOURCES.txt 1 2016-10-17 11:17 EGG-INFO/zip-safe 1 2016-10-17 11:17 EGG-INFO/top_level.txt--------- ------- 299 5 files
nothing changed becasue you haven’t added search directory option into setup.py
edit setup.py
like below
from setuptools import setup,find_packagespackage = 'name'version = '0.1'setup(name=package, version=version, description="description", packages=find_packages(), url='url')
resetup it again
then you will find something changed
cli:~/demo$ unzip -l dist/name-0.1-py2.7.egg Archive: dist/name-0.1-py2.7.egg Length Date Time Name--------- ---------- ----- ---- 137 2016-10-17 11:33 EGG-INFO/SOURCES.txt 176 2016-10-17 11:33 EGG-INFO/PKG-INFO 1 2016-10-17 11:33 EGG-INFO/dependency_links.txt 5 2016-10-17 11:33 EGG-INFO/top_level.txt 1 2016-10-17 11:33 EGG-INFO/zip-safe 75 2016-10-17 11:30 demo/__init__.py 341 2016-10-17 11:33 demo/__init__.pyc--------- ------- 736 7 files
we have __init__.py
in our package now
now install it using python setup.py install
, and import it in python
>>> import demo>>> demo.test()hello world>>>
great it works now
- python Setuptools
- python安装python-setuptools
- 使用setuptools自动安装python模块(setuptools)
- python安装之setuptools
- python的setuptools
- cygwin 安装 python setuptools
- Python--Setuptools的安装
- python setuptools安装方法
- python setuptools安装
- setup python setuptools
- python setuptools安装
- python下setuptools安装
- python离线安装setuptools
- python setuptools工具
- python setuptools工具打包
- Python深入:setuptools简介
- python安装setuptools
- python 缺少 setuptools
- android 文件系统升级 boot.img
- 数据存储(五种方式三)-ContentProvider
- struts中路径匹配原则
- Spring boot 使用restful风格的spring security login
- CentOS 安装rz和sz命令
- python Setuptools
- jConsole及visual VM通过JMX远程监控hbase的regionserver
- Java逻辑运算符
- android中的高级组件(三)(ExpandableListView,ImageSwitcher,Gallery)
- OS X EL Capitan安装CocoaPods遇过的坑,希望有帮助
- openwrt winshak 抓取无线beacon帧
- Archlinux实现自动登录、自动进入图形界面和自动连接路由器wifi
- Retrofit 多种提交方式 表单提交、多文件上传
- Elasticsearch 部署以及插件安装(win7)