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 ...
随机推荐
- 解决excel日期变成数字的问题
在Excel中如果单元格的公式是日期格式,那么引用后的数值是错误的[不是日期格式而被转换成数字类型了],这种情况显然不是我们想要的结果 解决办法: 在公式中强制转成文本类型即可(="Date ...
- Sql控制反转小尝试
假想用配置Sql语句的方式来完毕一个处理逻辑,而且映射到一个Url,这样当请求这个url的时候,运行前面配置的sql. 以下的一段详细配置,比如 当请求pagerlistdept.do的时候,会传入參 ...
- spring 读取配置文件,将值注入到静态字段
resources/config/config-dev.properties es.ip.node=xxxxxxxcluster.name=xxxxxxxclient.transport.sniff= ...
- 【摘录】在Windows平台上使用Objective-C
虽然到目前为止最好的Objective-C 编码平台来自苹果公司,但它们绝不仅适用于苹果公司的平台.Objective-C 在Linux.BSD 甚至Windows 等其他平台都有相当久远的历史.根据 ...
- Android Studio “懒人”必备插件android layout id converter
在一个布局文件里.假设定义了非常多非常多id,代码中一个个findview是一件非常枯燥而且浪费时间的事情. 所以这里向大家推荐一个必备插件android layout id converter. 配 ...
- register_shutdown_function函数详解--脚本退出时执行回调函数
register_shutdown_function — Register a function for execution on shutdown. ps:Registers a callback ...
- 【Linux】Ubuntu配置服务自启动 sysv-rc-conf
在Ubuntu下,配置服务系统开机自启动,使用的不是chkconfig,而是sysv-rc-conf. 且看如下: 安装: sudo apt-get install sysv-rc-conf 帮助信息 ...
- C#中添加三个线程同时启动执行某一方法,并依次调用某方法中的循环打印输。
添加三个线程同时启动执行某一方法,并依次调用某方法中的打印输:ABC ABC ABC ABC 实现代码如下: using System; using System.Collections.Generi ...
- 国外某牛人的JsonModelBinder 实现 MVC 3.0
public class JsonModelBinder : DefaultModelBinder { public override object BindModel(ControllerConte ...
- angularjs中templateUrl的路径问题
angularjs中templateUrl的路径问题 templateUrl的相对路径是现对于app主页面的,因为template使用js来加载的.