Python之包管理工具
安装Python包的过程中,经常涉及到distutils、setuptools、distribute、setup.py、easy_install、easy_install和pip等等。
distuils
distutils 是 python 标准库的一部分,这个库的目的是为开发者提供一种方便的打包方式, 同时为使用者提供方便的安装方式。
经常使用的setup.py就是基于distutils实现的,然后通过setup.py就可以进行打包或者安装了。
[root@node175 webdemo]# ls -a -l
总用量 20
drwxr-xr-x 5 root root 126 1月 5 17:25 .
drwxr-xr-x. 45 root root 4096 1月 5 14:50 ..
drwxr-xr-x 8 root root 4096 1月 5 14:53 .git
-rw-r--r-- 1 root root 0 1月 5 14:45 LICENSE
-rw-r--r-- 1 root root 0 1月 5 14:45 README.md
-rw-r--r-- 1 root root 226 1月 5 14:48 requirement.txt
-rw-r--r-- 1 root root 607 1月 5 14:50 setup.cfg
-rw-r--r-- 1 root root 355 1月 5 14:47 setup.py
drwxr-xr-x 2 root root 24 1月 5 14:46 webdemo
这个是一个最简单的Python项目目录:
源代码放在子目录Webdemo/下,然后包含了软件包管理的所需的文件:
- setup.py
- setup.cfg
- requirements.txt
- LICENSE
- README
set.py
#encoding=utf-8
import setuptools
# In Python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.Python.org/issue15881#msg170215
try:
import multiprocessing # noqa
except ImportError:
pass
setuptools.setup(
setup_requires=['pbr'], pbr=True)
setup.cfg
[metadata]
name = webdemo
version = 0.0.1
summary = Web Application Demo
description-file = README.md
author = author
author-email = author@example.com
classifier =
Environment :: Web Environment
Intended Audience :: Developers
Intended Audience :: Education
License :: OSI Approved :: GNU General Public License v2 (GPLv2)
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
[global]
setup-hooks =
pbr.hooks.setup_hook
[files]
packages = webdemo
[entry_points]
console_scripts =
只包含最基本的信息,接下来是requirements.txt文件:
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
pbr<2.0,>=0.11
配合git:
git init
git add .
git commit -m "init project"
git tag -a 0.0.1 -m "version 0.01"
然后就可以使用Python setup.py sdist命令来生成一个0.0.1版本的源码归档了:
python setup.py sdist
查看文件:
[root@node175 webdemo]# tree
.
├── AUTHORS
├── ChangeLog
├── dist
│ └── webdemo-0.0.1.tar.gz #生成的压缩包
├── LICENSE
├── README.md
├── requirement.txt
├── setup.cfg
├── setup.py
├── webdemo
│ └── __init__.py
└── webdemo.egg-info
├── dependency_links.txt
├── entry_points.txt
├── not-zip-safe
├── pbr.json
├── PKG-INFO
├── SOURCES.txt
└── top_level.txt
3 directories, 16 files
使用者就可以解压缩这个包然后执行 python setup.py install进行安装,然后就可以使用这个模块了;
setuptools 与 distribute
setuptools 是对 distutils 的增强,尤其是引入了包依赖管理。我们可以通过ez_setup.py来安装setuptools
至于distribute,它是setuptools的一个分支版本。分支的原因是有一部分开发者认为 setuptools 开发太慢。但现在,distribute 又合并回了 setuptools 中,所以可以认为它们是同一个东西。
前面看到setup.py可以创建一个压缩包,而setuptools使用了一种新的文件格式(.egg),可以为Python包创建 egg文件。setuptools 可以识别.egg文件,并解析、安装它;
当安装好setuptools/distribute之后,我们就可以直接使用easy_install这个工具了:
- 从PyPI上安装一个包:当使用 easy_install package 命令后,easy_install 可以自动从 PyPI 上下载相关的包,并完成安装,升级
- 下载一个包安装:通过 easy_install package.tgz 命令可以安装一个已经下载的包
- 安装egg文件:通过 easy_install package.egg 可以安装一个egg格式的文件
setuptools/distribute和easy_install之间的关系:
- setuptools/distribute 都扩展了 distutils,提供了更多的功能
- easy_install是基于setuptools/distribute的一个工具,方便了包的安装和省级
pip
pip install pkg
Python之包管理工具的更多相关文章
- Python的包管理工具Pip (zz )
Python的包管理工具Pip 接触了Ruby,发现它有个包管理工具RubyGem很好用,并且有很完备的文档系统http://rdoc.info 发现Python下也有同样的工具,包括easy_ins ...
- Python的包管理工具
Python的包管理工具 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.为什么使用包管理 Python的模块或者源文件直接可以复制到目标项目目录中,就可以导入使用了. 但是为了 ...
- 【转载】Python的包管理工具Pip
接触了Ruby,发现它有个包管理工具RubyGem很好用,并且有很完备的文档系统http://rdoc.info 发现Python下也有同样的工具,包括easy_install和Pip.不过,我没有细 ...
- Python的包管理工具Pip
接触了Ruby,发现它有个包管理工具RubyGem非常好用,而且有非常完备的文档系统http://rdoc.info 发现Python下也有相同的工具,包含easy_install和Pip.只是,我没 ...
- Python之包管理工具:distutils、setuptools、distribute、setup.py、easy_install、easy_install、pip
在安装Python包的过程中,经常涉及到distutils.setuptools.distribute.setup.py.easy_install.easy_install和pip等等. 介绍:htt ...
- 5、Python之包管理工具pip
pip提供我们各色各样的软件(第三方库),而这些第三方库又可以给我们实现各种各样不同的功能,科学计算.画图.操作文件.聊天-- 我们可以通过Cmd终端.Pycharm.Jupyter三种平台使用pip ...
- Python 的包管理工具 distribute, setuptools, easy_install命令与 pip命令
Setuptools 是 Python Enterprise Application Kit (PEAK)的一个副项目,它是 Python 的disutils工具的增强工具,可以让程序员更方便地创建和 ...
- Python的包管理工具--PIP安装使用
最新安装方式 # wget https://bootstrap.pypa.io/get-pip.py # python get-pip.py // 使用该方式安装已经不再要求提前安装setuptoo ...
- 【跟我一起学Python吧】Python的包管理工具
刚开始学习Python时,在看文档和别人的blog介绍安装包有的用easy_install, setuptools, 有的使用pip,distribute,那麽这几个工具有什么关系呢,看一下下面这个图 ...
- Python的包管理工具easy_install, setuptools, pip,distribute介绍
1.相互之间的关联 easy_install, setuptools, pip,distribute,这几个工具的联系,如下图: 可以看到distribute是setuptools的取代,pip是ea ...
随机推荐
- IDEA 禁止自动导入引用包 取消import包
http://www.oschina.net/question/2010061_226765 我想拷贝一小段代码,或者我就是不想引入拷贝来的包,我该怎么取消掉idea的自动导入import包呢? 找到 ...
- .NET Framework 工具
您可以使用 .NET Framework 工具轻松创建.部署和管理面向 .NET Framework 的应用程序和组件. 此节中介绍的大部分 .NET Framework 工具将自动随 Visual ...
- iOS编程(双语版)-视图-Autolayout代码初步
一谈到Autolayout,初学者肯定想到的是IB中使用拖拽啊,pin啊各种鼠标操作来进行添加各种约束. 今天我们要聊得是如何利用代码来添加视图间的约束. 我们来看一个例子: (Objective-C ...
- Ganglia监控Hadoop集群的安装部署
一. 安装环境 Ubuntu server 12.04 安装gmetad的机器:192.168.52.105 安装gmond的机器:192.168.52.31,192.168.52.32,192.16 ...
- LCD显示——点阵字体
Bitmap font 点阵字体是把每一个字符都分成16×16或24×24个点,然后用每个点的虚实来表示字符的轮廓. 点阵字体优点是显示速度快,不像矢量字体需要计算:其最大的缺点是不能放大,一旦放大后 ...
- 一个JAVA的WEB服务器事例
其实编写一个入门级别的JAVA的WEB服务器,很简单,用SOCKET类即可实现.相关内容可以参考:http://www.cnblogs.com/liqiu/p/3253022.html 一.首先创建一 ...
- javascript数组去重复
数组去重 知乎上看到有人去腾讯面试,然后发了面试的js题目,有一个是数组去重 我的土办法 var arr = ['a', 'g', 'q', 'd', 'a', 'e', 'q']; console. ...
- python environ PYTHON_EGG_CACHE
My first thought was "Wow, that's quite a long way of telling me to 'just quit.'" Not want ...
- sqlserver 建表语句,获取建表语句的存储过程,包括排序规则,索引,字段说明,支持同时生成多个表
先创建一个分割表名的分割函数 --表值函数用以截取字符串 --如果为其添加一列主键id,则其顺序就会固定了 create FUNCTION [Split](@text NVARCHAR(max)) ) ...
- tcp 两个重要窗口:滑动窗口 和 拥塞窗口
一:滑动窗口是接受数据端使用的窗口大小,用来告知发送端接收端的缓存大小,以此可以控制发送端发送数据的大小,从而达到流量控制的目的,对应==>rwnd:接收端窗口(receiver window) ...