Python的包管理工具
来源:互联网 发布:网络俗语hp是什么意思 编辑:程序博客网 时间:2024/05/29 08:13
Python的包管理工具
- 博客分类:
- Python
刚开始学习Python时,在看文档和别人的blog介绍安装包有的用easy_install, setuptools, 有的使用pip,distribute,那麽这几个工具有什么关系呢,看一下下面这个图就明白了
可以看到distribute是setuptools的取代,pip是easy_install的取代。
关于这些包工具可以参考 http://guide.python-distribute.org/installation.html#installing-pip
下面简单的介绍一下:
Distribute是对标准库disutils模块的增强,我们知道disutils主要是用来更加容易的打包和分发包,特别是对其他的包有依赖的包。
Distribute被创建是因为Setuptools包不再维护了。
安装Distribute
可以通过distribute_setup.py 脚本来安装Distribute,也可以通过easy_install, pip,源文件来安装,不过使用distribute_setup.py来安装是最简单和受欢迎的方式
$ curl -0 http://python-distribute.org/distribute_setup.py
$ sudo python distribute_setup.py
Pip 是安装python包的工具,提供了安装包,列出已经安装的包,升级包以及卸载包的功能。
Pip 是对easy_install的取代,提供了和easy_install相同的查找包的功能,因此可以使用easy_install安装的包也同样可以使用pip进行安装。
安装Pip
Pip的安装可以通过源代码包,easy_install或者脚本。
下面介绍一下各种安装方法:
源代码方式:
$ wget http://pypi.python.org/packages/source/p/pip/pip-0.7.2.tar.gz (替换为最新的包)$ tar xzf pip-0.7.2.tar.gz$ cd pip-0.7.2$ python setup.py install
easy_install:
$ easy_install pip
get_pip.py 脚本:
$ curl -0 https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ sudo python get-pip.py
OK, 下面来看一下Pip的使用
安装package
$ pip install Markdown
列出安装的packages
$ pip freeze
安装特定版本的package
通过使用==, >=, <=, >, <来指定一个版本号。
$ pip install 'Markdown<2.0'
$ pip install 'Markdown>2.0,<2.0.3'
升级包
升级包到当前最新的版本,可以使用-U 或者 --upgrade
$ pip install -U Markdown
卸载包
$ pip uninstall Markdown
查询包
pip search "Markdown"
PS -- 包安装后的py文件路径:/usr/local/lib/python2.7/dist-packages
Installing the Package Tools
In the current state of packaging in Python, one needs a set of tools to easily manipulate the packaging ecosystem. There are two tools in particular that are extremely handy in the current ecosystem. There is a third tool, Virtual Environments, that will be discussed later in this documentation that will assist in isolating a packaging ecosystem from the global one. The combination of these tools will help to find, install and uninstall packages.
Distribute
Distribute is a collection of enhancements to the Python standard library module: distutils (for Python 2.3.5 and up on most platforms; 64-bit platforms require a minimum of Python 2.4) that allows you to more easily build and distribute Python packages, especially ones that have dependencies on other packages.
Distribute was created because the Setuptools package is no longer maintained. Third-party packages will likely require setuptools, which is provided by the Distribute package. Therefore, anytime time a packages depends on the Setuptools package, Distribute will step in to say it already provides the setuptools module.
See also
Distribute documentation.
Installation Instructions
Distribute can be installed using the distribute_setup.py script. It can also be installed using easy_install, pip, the source tarball, or the egg distribution. distribute_setup.py is the simplest and preferred way to install Distribute on all systems.
Download distribute_setup.py and execute it, using the Python interpreter of your choice.
From the *nix shell you can do:
Note
For those on Mac OS X, you can use curl -O <url> instead of wget.
See also
The development version of Distribute can be found at: http://bitbucket.org/tarek/distribute/
Pip Installs Python (Pip)
Pip is an installer for Python packages written by Ian Bicking. It can install packages, list installed packages, upgrade packages and uninstall packages.
The pip application is a replacement for easy_install. It uses mostly the same techniques for finding packages, so packages that were made easy_installable should be pip-installable as well.
See also
Pip Documentation and Pip PyPI description
Note
??? Pip requirements
Installing Pip
The Pip installer can be installed using the source tarball or using easy_install. The source tarball is the recommended method of installation.
The latest version of the source tarball can be obtained from PyPI:
Or the easy_install application can be used:
The pip application is now installed.
Note
pip is complementary with Virtual Environments, and it is encouraged that you use Virtual Environments to isolate your installation.
Installing a package
Let’s install the Markdown package:
Markdown is now installed; you can import and use it:
Listing installed packages
To list installed packages and versions, use the freeze command:
Note
The wsgiref package is a part of the Python standard library. Currently it is the only standard library package that includes package metadata, so it is the only standard library package whose presence pip reports.
Installing specific versions
You can also give pip a version specifier for a package using one or more of ==, >=, >, <, <=:
This will find your current installation of Markdown 2.0.3, automatically uninstall it, and install Markdown 1.7 (the latest version in the 1.x series) in its place. You can even combine version specifiers with a comma:
Upgrading
If you want to upgrade a package to its most recent available version, use the -U or --upgrade flag:
Uninstalling
Now let’s uninstall Markdown:
After showing you which files/directories will be removed and requesting confirmation, pip will uninstall everything installed by the Markdown package.
Note
Pip inside a Virtual Environment will only uninstall packages installed within that virtual environment. For instance, if you try to pip uninstall wsgiref it will refuse, because the reference is within the global Python’s standard library.
- Python的包管理工具
- Python的包管理工具
- python的包管理工具
- Python的包管理工具
- Python的包管理工具
- Python的包管理工具
- Python的包管理工具
- Python的包管理工具
- Python的包管理工具
- Python的包管理工具
- Python的包管理工具
- Python的包管理工具Pip
- 安装Python 的包管理工具
- Python的包管理工具Pip
- Python的包管理工具Pip
- Python的包管理工具Pip
- 【Python】Python的包管理工具Pip
- python的安装包管理工具easy_install
- cin,cout的加速
- VS2010 LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- oracle 审计
- Linux Kernel Porting CPU 方法概要
- 1018. 锤子剪刀布 (20) PAT+运行超时
- Python的包管理工具
- 正则表达式文献
- IT人,如何提升自己
- ORA-12520错误解决方法
- struts2常量配置详情
- Oracle之索引(认证考试指南全册)
- protobuf简介
- 404页面的简洁版
- oracle正则表达式函数 匹配