zoukankan      html  css  js  c++  java
  • pip;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

    转自:http://www.yeolar.com/note/2012/08/18/setuptools-pip-virtualenv/

    几个Python配置工具简介:setuptools、pip、virtualenv

    本篇快速总结几个Python的常见配置工具,包括setuptools、pip、virtualenv。

    setuptools

    setuptools管理Python的第三方包,将包安装到site-package下,安装的包后缀一般为.egg,实际为ZIP格式。默认从 http://pypi.python.org/pypi 下载包,能够解决Python包的依赖关系。

    安装了setuptools之后即可用 easy_install 命令安装包,有多种安装方式可以选择。

    # easy_install PACKAGE          # 普通安装
    # easy_install /home/yeolar/pkg/PACKAGE.egg # 从本地或网络文件系统中安装
    # easy_install http://trac-hacks.org/svn/iniadminplugin/0.11/ # 从指定的下载路径安装
    # easy_install http://pypi.python.org/simple/PACKAGE/PACKAGE-0.1.2.4.tar.gz # 从URL源码包安装,条件是PACKAGE-0.1.2.4.tar.gz包中的根目录中必须包括setup.py文件
    # easy_install -f http://pypi.python.org/simple/ PACKAGE # 从web上面搜索包,并自动安装
    # easy_install PACKAGE==0.1.2.1 # 指定包的版本,如果指定的版本高于现已安装的版本就是升级了
    # easy_install -U PACKAGE       # 升级到最新版本,不指定版本就会升级到最新版本
    # easy_install -U PACKAGE==0.1.2.2 # 升级到指定版本
    # easy_install -m PACKAGE       # 卸载包,卸载后还要手动删除遗留文件
    

    pip

    pip也是一个包管理工具,它和setuptools类似,如果使用virtualenv,会自动安装一个pip。

    # pip install PACKAGE           # 安装包
    # pip -f URL install PACKAGE    # 从指定URL下载安装包
    # pip -U install PACKAGE        # 升级包
    

    virtualenv

    virtualenv是一个Python环境配置和切换的工具,可以用它配置多个Python运行环境,和系统中的Python环境隔离,即所谓的沙盒。沙盒的好处包括:

    1. 解决库之间的版本依赖,比如同一系统上不同应用依赖同一个库的不同版本。
    2. 解决权限限制,比如你没有 root 权限。
    3. 尝试新的工具,而不用担心污染系统环境。
    $ virtualenv py-for-web
    

    这样就创建了一个名为py-for-web的Python虚拟环境,实际上就是将Python环境克隆了一份。然后可以用source py-for-web/bin/activate 命令来更新终端配置,修改环境变量。接下来的操作就只对py-for-web环境产生影响了,可以使用 pip 命令在这里安装包,当然也可以直接安装。

    $ source py-for-web/bin/activate    # 启用虚拟环境
    $ deactivate                        # 退出虚拟环境
    

    有个virtualenv-sh包,对virtualenv做了一些终端命令的增强。安装之后,在~/.bashrc中添加配置:

    . /usr/local/bin/virtualenv-sh.bash
    

    它提供的几个常用的命令如:

    mkvirtualenv <env_name>     在$WORKON_HOME创建虚拟环境
    rmvirtualenv <env_name>     删除虚拟环境
    workon [<env_name>]         切换到虚拟环境
    deactivate                  退出虚拟环境
    lsvirtualenvs               列出全部的虚拟环境
    cdvirtualenv [subdir]       进入虚拟环境的相应目录
    

    $WORKON_HOME 的默认值为 ${HOME}/.virtualenvs 。

    链接: http://www.yeolar.com/note/2012/08/18/setuptools-pip-virtualenv/
  • 相关阅读:
    详解MathType中如何插入特殊符号
    详解如何将MathType嵌入word中
    MathType公式编辑器快捷键操作
    MathType初级教程:怎么安装MathType
    AOPR密码过滤器
    教您如何在Word的mathtype加载项中修改章节号
    在word文档中如何插入Mathtype公式
    详解MathType中如何更改公式颜色
    静态缓存和动态缓存
    ThinkPHP U函数生成URL伪静态
  • 原文地址:https://www.cnblogs.com/-colin/p/9011110.html
Copyright © 2011-2022 走看看