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. 移动对meta的定义

    以下是meta每个属性详解 尤其要注意的是content里多个属性的设置一定要用分号+空格来隔开,如果不规范将不会起作用. 一.<meta http-equiv="Content-Ty ...

  2. Java中实现复制文件或文件夹

     拷贝一个文件的算法比较简单,当然,可以对它进行优化,比如使用缓冲流,提高读写数据的效率等.但是在复制文件夹时,则需要利用Flie类在目标文件夹中创建相应的目录,并且使用递归方法. [java] vi ...

  3. 【转】堆栈跟踪中收到一个UnhandledExceptionFilter调用时,如何查找问题异常堆栈

    定义没有异常处理程序来处理引发的异常时调用UnhandledExceptionFilter函数.函数通常将异常传递到捕获并处理它所尝试的 Ntdll.dll 文件. 在某些情况下,在其中存在的进程内存 ...

  4. Android入门:用HttpClient模拟HTTP的GET和POST请求

    一.HttpClient介绍   HttpClient是用来模拟HTTP请求的,其实实质就是把HTTP请求模拟后发给Web服务器:   Android已经集成了HttpClient,因此可以直接使用: ...

  5. C# Read/Write another Process' Memory z

    http://www.codeproject.com/Articles/670373/Csharp-Read-Write-another-Process-Memory This article aim ...

  6. HDU-4882 ZCC Loves Codefires

    http://acm.hdu.edu.cn/showproblem.php?pid=4882 ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Ot ...

  7. bug报告-常用词汇中英对照表

  8. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 page_should_contain_list(self, locator, message='', loglevel='INFO')

    def page_should_contain_list(self, locator, message='', loglevel='INFO'): """Verifies ...

  9. python easy_install centos 下安装过程和原理解析

    一.easy_install 安装过程 其安装过程有很多种,我也找了很多的例子,但是结果都不太好,以下方法的结果是不错的. easy_install与yum类似,使用easy_install,可以轻松 ...

  10. [GRYZ]寒假模拟赛

    写在前面 这是首次广饶一中的OIERS自编自导,自出自做(zuo)的模拟赛. 鉴于水平气压比较低,机(wei)智(suo)的WMY/XYD/HYXZC就上网FQ下海找了不少水(fei)题,经过他们优( ...