pip 有许多子命令:“search”、“install”、“uninstall”、“freeze”等等。(请参阅 指南以了解 pip 的完整文档。)

    您可以通过指定包的名称来安装最新版本的包:

    1. (tutorial-env) $ pip install novas
    2. Collecting novas
    3. Downloading novas-3.1.1.3.tar.gz (136kB)
    4. Installing collected packages: novas
    5. Running setup.py install for novas
    6. Successfully installed novas-3.1.1.3

    如果你重新运行这个命令, 会注意到已经安装了所请求的版本并且什么都不做。您可以提供不同的版本号来获取该版本,或者您可以运行 pip install —upgrade 将软件包升级到最新版本:

    1. (tutorial-env) $ pip install --upgrade requests
    2. Collecting requests
    3. Installing collected packages: requests
    4. Uninstalling requests-2.6.0:
    5. Successfully uninstalled requests-2.6.0
    6. Successfully installed requests-2.7.0

    pip uninstall 后跟一个或多个包名称将从虚拟环境中删除包。

    pip list 将显示虚拟环境中安装的所有软件包:

    1. (tutorial-env) $ pip list
    2. novas (3.1.1.3)
    3. numpy (1.9.2)
    4. pip (7.0.3)
    5. requests (2.7.0)
    6. setuptools (16.0)

    pip freeze` 将生成一个类似的已安装包列表,但输出使用 期望的格式。一个常见的约定是将此列表放在 requirements.txt 文件中:

    1. Collecting novas==3.1.1.3 (from -r requirements.txt (line 1))
    2. ...
    3. Collecting numpy==1.9.2 (from -r requirements.txt (line 2))
    4. ...
    5. Collecting requests==2.7.0 (from -r requirements.txt (line 3))
    6. ...
    7. Installing collected packages: novas, numpy, requests
    8. Running setup.py install for novas
    9. Successfully installed novas-3.1.1.3 numpy-1.9.2 requests-2.7.0

    pip 有更多选择。有关 的完整文档,请参阅 安装 Python 模块 指南。当您编写一个包并希望在 Python 包索引中使它可用时,请参考 指南。