1.什么是setuptools

setuptoolssetuptools是 Python Enterprise Application Kit(PEAK)的一个副项目,是Python distutils增强版的集合,它可以帮助我们更简单的创建和分发Python包,尤其是拥有依赖关系的。Python还可以帮助我们管理第三方依赖包。

2.安装setuptools

我们使用ez_setup.py来安装,这是 setuptools 自豪的一种安装方式,会自动下载匹配当前Python版本的安装包来安装。

ez_setup.py文件:http://download.csdn.net/detail/chenjintaoxp/6399857

Window中cmd下执行 python ez_setup.py

3利用setuptools制作egg

1〉在C:\Demo\下创建setup.py . (Demo相当于工程)

#from distutils.core import setup
from setuptools import setup, find_packages
setup(
name = 'foo',#包名
version = '0.0.1',#版本号
packages = find_packages()#搜索Demo下的包
)

2〉C:\Demo\创建包foo,C:\Demo\foo\__init__.py

#!/usr/bin/python
def say():
print 'hello' if __name__ == '__main__':
say()

3〉cmd进入C:\Demo,执行python setup.py bdist_egg,会在C:\demo\dist下找到生成的egg文件:foo-0.0.1-py2.7.egg (Python2.7环境)

C:\Demo 的目录

2013/10/15  00:10    <DIR>          .
2013/10/15 00:10 <DIR> ..
2013/10/15 00:11 <DIR> foo
2013/10/15 00:10 173 setup.py
1 个文件 173 字节
3 个目录 15,546,511,360 可用字节 C:\Demo>python setup.py bdist_egg
running bdist_egg
running egg_info
creating foo.egg-info
writing foo.egg-info\PKG-INFO
writing top-level names to foo.egg-info\top_level.txt
writing dependency_links to foo.egg-info\dependency_links.txt
writing manifest file 'foo.egg-info\SOURCES.txt'
reading manifest file 'foo.egg-info\SOURCES.txt'
writing manifest file 'foo.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\foo
copying foo\__init__.py -> build\lib\foo
creating build\bdist.win32
creating build\bdist.win32\egg
creating build\bdist.win32\egg\foo
copying build\lib\foo\__init__.py -> build\bdist.win32\egg\foo
byte-compiling build\bdist.win32\egg\foo\__init__.py to __init__.pyc
creating build\bdist.win32\egg\EGG-INFO
copying foo.egg-info\PKG-INFO -> build\bdist.win32\egg\EGG-INFO
copying foo.egg-info\SOURCES.txt -> build\bdist.win32\egg\EGG-INFO
copying foo.egg-info\dependency_links.txt -> build\bdist.win32\egg\EGG-INFO
copying foo.egg-info\top_level.txt -> build\bdist.win32\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist\foo-0.0.1-py2.7.egg' and adding 'build\bdist.win32\egg' to it
removing 'build\bdist.win32\egg' (and everything under it) C:\Demo>

4〉利用easy_install来安装生成的
foo-0.0.1-py2.7.egg包

 C:\Demo\dist 的目录

2013/10/15  00:13    <DIR>          .
2013/10/15 00:13 <DIR> ..
2013/10/15 00:13 1,334 foo-0.0.1-py2.7.egg
1 个文件 1,334 字节
2 个目录 15,546,499,072 可用字节 C:\Demo\dist>easy_install foo-0.0.1-py2.7.egg
Processing foo-0.0.1-py2.7.egg
Copying foo-0.0.1-py2.7.egg to c:\python27\lib\site-packages
Adding foo 0.0.1 to easy-install.pth file Installed c:\python27\lib\site-packages\foo-0.0.1-py2.7.egg
Processing dependencies for foo==0.0.1
Finished processing dependencies for foo==0.0.1 C:\Demo\dist>

从安装的过程来看,egg包是安装在

c:\python27\lib\site-packages\

5〉测试结果如下

In [1]: import foo

In [2]: foo.say()
hello In [3]:

说明foo包已经安装成功。

foo包的Demo工程地址:http://download.csdn.net/detail/chenjintaoxp/6400019

4.使用setuptools的easy_install(管理第三方包)

安装一个包:
#通过包名安装一个普通的包(从PyPI搜索自动安装)
ex:easy_install SQLObject
#在指定的下载URL中,通过包名安装和更新包
ex:easy_install -f http://pythonpaste.org/package_index.html SQLObject
#通过source发布的URL,下载,编译,安装包
ex:easy_install http://example.com/path/to/MyPackage-1.2.3.tgz
#通过egg文件去安装包(如:foo包的安装)
ex:easy_install /my_downloads/OtherPackage-3.2.1-py2.3.egg
#更新已经安装的包到最近版本
ex:easy_install --upgrade PyProtocols 更新一个包:
#将目前包更新到2.0版本
ex:easy_install "SomePackage==2.0"
#将目前包更新到>2.0的一个版本
ex:easy_install "SomePackage>2.0"
#更新到包的最新版本
ex:easy_install --upgrade SomePackage
#通过URL来更新
ex:easy_install -f http://example.com/downloads ExamplePackage
ex:easy_install http://example.com/downloads/ExamplePackage-2.0-py2.4.egg
ex:easy_install my_downloads/ExamplePackage-2.0.tgz 卸载一个包:
#通过包名卸载包
ex:easy_install -mxN PackageName

详细easy_install使用参照:http://peak.telecommunity.com/DevCenter/EasyInstall

setuptools的使用的更多相关文章

  1. 【原】关于Python中setuptools安装的问题

    在生成package的时候,需要在setup.py中引入setuptools包,可是却报告如下错误: ImportError: No module named setuptools 解决办法就是下载s ...

  2. Linux从零单排(二):setuptools、pip、anaconda2的环境配置

    为了更方便的使用Python的类库,需要进行相应的配置 (一)setuptools的配置 1.setuptools的下载 命令行输入wget https://pypi.python.org/packa ...

  3. Python中setuptools做什么用的?

    概括 setuptools是 Python Enterprise Application Kit(PEAK)的一个副项目,它 是一组Python的 distutilsde工具的增强工具(适用于 Pyt ...

  4. python3.5学习笔记:linux6.4 安装python3 pip setuptools

    前言: python3应该是python的趋势所在,当然目前争议也比较大,这篇随笔的主要目的是记录在linux6.4下搭建python3环境的过程 以及碰到的问题和解决过程. 另外,如果本机安装了py ...

  5. python setuptools工具打包

    http://blog.csdn.net/five3/article/details/7847551http://blog.csdn.net/reyoung1110/article/details/7 ...

  6. Python3 windows如何安装模块 setuptools

    下载的module解压后里面有setup.py文件,如果打开setup.py文件里面有这段代码: from setuptools import setup ... setup( ... 这种的都需要调 ...

  7. ez_setup.py(安装python下setuptools用)

    #!python"""Bootstrap setuptools installation If you want to use setuptools in your pa ...

  8. python安装setuptools

    http://wenku.baidu.com/link?url=I-FCVFpHbP2oyCt1Gjb1X5xHk4P475dVU3j8rWd4b4VSuD-Wd86LdbC7bdYskZdtDfGK ...

  9. python打怪之路【第二篇】:ImportError: No module named setuptools

    在python安装第三方模块时出现如下错误: python错误:ImportError: No module named setuptools这句错误提示的表面意思是:没有setuptools的模块, ...

  10. Python之No module named setuptools 安装pip

    早上运行程序的时候发现没有引入相应的module,然后使用pip去安装的时候发现自己没有在安装pip,于是在自己的软件群里边找见了pip安装包,在pip的解压目录下运行python setup.py ...

随机推荐

  1. jquery实现点击按钮滑动到指定位置

    <body> <script type="text/javascript"> function click_scroll() { var scroll_of ...

  2. MySQL5.6 replication architecture --原图来自姜承尧

  3. Android selector item 属性大全(按钮按下不同效果)

    <selector>         必须.必须是根元素.包含一个或多个<item>元素.          Attributes:             xmlns:and ...

  4. codedorces 260 div2 A题

    水题,扫描一遍看是否出现价格低质量高的情况. #include<cstdio> #include<string> #include<vector> #include ...

  5. hdu 4720 计算几何简单题

    昨天用vim练了一道大水题,今天特地找了道稍难一点的题.不过也不是很难,简单的计算几何而已.练习用vim编码,用gdb调试,结果居然1A了,没调试...囧... 做法很简单,无非就是两种情况:①三个巫 ...

  6. PHP $_SERVER的详细参数及说明

    $_SERVER['PHP_SELF']#当前正在执行脚本的文件名,与documentroot相关. $_SERVER['argv']#传递给该脚本的参数. $_SERVER['argc']#包含传递 ...

  7. Seam carving 学习笔记

    今天首次接触了图像编辑中的seam carving知识,感觉挺神奇的.虽然我自己可能理解的不是很深刻,但是记录下来,总是好的. seam carving直接翻译过来是“线裁剪”的意思.它的主要用途是对 ...

  8. CodeForce---Educational Codeforces Round 3 Load Balancing 正题

    看到这题是我的想法就是肯定跟平均值有关但是接下来就不知道怎么做了 看完大神的正解数之后,原来发现是这么简单,但是就是不知道为啥一定是平均值和平均值加1,而不是平均值和平均值减1: 好啦下面就贴出大神的 ...

  9. Spark RDD概念学习系列之Spark的数据存储(十二)

    Spark数据存储的核心是弹性分布式数据集(RDD). RDD可以被抽象地理解为一个大的数组(Array),但是这个数组是分布在集群上的. 逻辑上RDD的每个分区叫一个Partition. 在Spar ...

  10. HDU 1702 队列与栈的简单运用http://acm.hdu.edu.cn/showproblem.php?pid=1702

    #include<stdio.h> #include<string.h> #include<queue> #include<stack> #define ...