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 ...
随机推荐
- JAVA-jar包下载地址
spring mvc常用jar包 commons-logging:http://commons.apache.org/proper/commons-logging/download_logging.c ...
- Java-Shiro(三):Shiro与Spring MVC集成
新建Java Daynamic Web项目 导入Spring.SpringMVC依赖包: 导入Spring & Spring MVC包(导入如下所有开发包): Spring AOP依赖扩展包: ...
- webkit-user-select:none 问题
webkit-user-select:none 问题 学习了:https://bugs.webkit.org/show_bug.cgi?id=82692 最近两天做移动端游戏举报页面.遇到一个问题,移 ...
- webstorm和intellij idea下如何自动编译sass和scss文件
webstorm和intellij idea下如何自动编译sass和scss文件 https://segmentfault.com/a/1190000008996504 https://www.jia ...
- Giraph源代码分析(九)—— Aggregators 原理解析
HamaWhite 原创.转载请注明出处!欢迎大家增加Giraph 技术交流群: 228591158 Giraph中Aggregator的基本使用方法请參考官方文档:http://giraph.apa ...
- [React] Use React.ReactNode for the children prop in React TypeScript components and Render Props
Because @types/react has to expose all its internal types, there can be a lot of confusion over how ...
- js获取当月最后一天
构造函数 new Date(); new Date(value); new Date(dateString); new Date(year, month[, day[, hour[, minutes[ ...
- KVM 虚拟化技术
1.1 前言 1.1.1 什么是虚拟化? 在计算机技术中,虚拟化(技术)或虚拟技术(英语:Virtualization)是一种资源管理技术,是将计算机的各种实体资源(CPU.内存.磁盘空间.网络适配器 ...
- guava 学习笔记 瓜娃(guava)的API快速熟悉使用
1,大纲 让我们来熟悉瓜娃,并体验下它的一些API,分成如下几个部分: Introduction Guava Collection API Guava Basic Utilities IO API C ...
- android studio中的常用快捷键
1.Ctrl+Alt+Space 这个类似Eclipse中的Alt+/,实现智能提示功能的 2.Ctrl+Y 删除当前行,Eclipse中是Ctrl+D,伤不起,每次都习惯性的按Ctrl+D,不删,反 ...