【转载】Python包管理工具pip与easy_install

简介:

     初学 Python,总是提示缺少各种各样的 Python 包,于是了解了下 Python 的包安装管理工具:

1.setuptools 中的 easy_install (Download, build, install, upgrade, and uninstall Python packages -- easily!)

easy_install 是 setuptools 包里的一个命令,所以想使用 easy_install 就得安装 setuptools 。

①可以直接下载setuptools-0.6c11.win32-py2.7.exe文件安装

下载地址:http://pypi.python.org/pypi/setuptools

      安装完成之后在 Python 安装目录下的 Scripts 目录下就会有 easy_install.exe,将 Scripts 加到Path 变量里,就可以使用它来安装 Python 包了,只需要将包名作为参数,它就会自动到 Pypi 里去查找并安装,例如:

easy_install SQLObject

②通过下载 ez_setup.py 脚本安装 setuptools

脚本下载地址:http://peak.telecommunity.com/dist/ez_setup.py

      安装效果应该是和方法①是一样的(但是这里下载的是setuptools-0.6c11-py2.7.egg),不过根据官网的文档,对于 64 位的机器,只能使用第二种方式进行安装。

2.pip(a tool for installing and managing Python packages, a replacement for easy_install)

      pip 的安装需要 setuptools 或者 distribute 如果你使用的是 Python3.x 那么就只能使用distribute 因为 Python3.x 不支持 setuptools 。

可以通过脚本 get-pip.py 来安装 pip,脚本下载地址:

https://raw.github.com/pypa/pip/master/contrib/get-pip.py 

下载后执行即可安装 pip 。

      安装完成之后相关的命令程序,同样会放到 Python 安装路径下的 Scripts 目录下,然后就可以用如下方式安装相关的包:

pip install SomePackage

 

      据说 pip 是 easy_install 的替代品,初学 Python,体会得不够深刻,期待后期补充,下面是 pip官网上对 pip 与 easy_install 进行的比较

pip is meant to improve on easy_install. Some of the improvements:

  • All packages are downloaded before installation. Partially-completed installation doesn’t occur as a result.
  • Care is taken to present useful output on the console.
  • The reasons for actions are kept track of. For instance, if a package is being installed, pip keeps track of why that package was required.
  • Error messages should be useful.
  • The code is relatively concise and cohesive, making it easier to use programmatically.
  • Packages don’t have to be installed as egg archives, they can be installed flat (while keeping the egg metadata).
  • Native support for other version control systems (Git, Mercurial and Bazaar)
  • Uninstallation of packages.
  • Simple to define fixed sets of requirements and reliably reproduce a set of packages.

pip doesn’t do everything that easy_install does. Specifically:

  • It cannot install from eggs. It only installs from source. (In the future it would be good if it could install binaries from Windows .exe or .msi – binary install on other platforms is not a priority.)
  • It is incompatible with some packages that extensively customize distutils or setuptools in their setup.py files.

pip is complementary with virtualenv, and it is encouraged that you use virtualenv to isolate your installation.


目录
相关文章
|
2天前
|
JSON 数据格式 开发者
pip和requests在Python编程中各自扮演着不同的角色
`pip`是Python的包管理器,用于安装、升级和管理PyPI上的包;`requests`是一个HTTP库,简化了HTTP通信,支持各种HTTP请求类型及数据交互。两者在Python环境中分别负责包管理和网络请求。
13 5
|
4天前
|
Python
在Python中快捷引入缺失包的技巧和实践
在Python中快捷引入缺失包的技巧和实践
10 0
|
9天前
|
域名解析 JSON API
Python小工具包
【5月更文挑战第2天】构建了一个Python小工具包,包含获取IP、域名解析、JSON格式化和时间戳转换的函数。通过`get_ip_address`和`resolve_domain`实现网络任务,`format_json`用于美化JSON数据,`timestamp_to_datetime`转换时间戳。这些函数可提高开发效率,易于整合到项目中,展现Python的简洁和灵活性。
19 1
Python小工具包
|
11天前
|
Linux Python Windows
Python更换国内pip源详细教程
Python更换国内pip源详细教程
|
11天前
|
网络协议 算法 网络架构
Python网络编程之udp编程、黏包以及解决方案、tcpserver
Python网络编程之udp编程、黏包以及解决方案、tcpserver
|
17天前
|
Python
【Python笔记】pip intall -e命令:让你的工程直接使用开源包的源码,可断点调试,修改源码!
【Python笔记】pip intall -e命令:让你的工程直接使用开源包的源码,可断点调试,修改源码!
15 0
|
17天前
|
机器学习/深度学习 缓存 程序员
Python包管理工具 pip 及其常用命令和参数用法
Python包管理工具 pip 及其常用命令和参数用法
63 0