How to use Pip and PyPI

来源:互联网 发布:淘宝卖家后台网址 编辑:程序博客网 时间:2024/06/04 00:42

原文链接:http://www.pythonforbeginners.com/basics/how-to-use-pip-and-pypi

Pip - Overview

The pip command is a tool for installing and managing Python packages, such as those found in the Python Package Index.

It’s a replacement for easy_install.

PIP Installation

Installing PIP is easy and if you’re running Linux, its usually already installed.

If it’s not installed or if the current version is outdated, you can use the package manager to install or update it.

On Debian and Ubuntu:
$ sudo apt-get install python-pip
On Fedora:
$ sudo yum install python-pip
If you are using Mac, you can simply install it through easy_install:
sudo easy_install pip

PyPI - the Python Package Index

Now, when PIP is installed, we need to find a package to install.

Packages are usually installed from the Python Package Index.

The Python Package Index is a repository of software for the Python programming language.

Getting Started with PIP

Now, when we know what PIP is and we have it installed on the computer, let’s see how to use it.

To install a package from the Python Package Index, just open up your terminal and type in a search query using the PIP tool.

PIP - Commands

Just typing pip in your terminal, should give you the following output on the screen:

Usage:  pip  [options]Commands:  install   Install packages.  uninstall     Uninstall packages.  freeze        Output installed packages in requirements format.  list          List installed packages.  show          Show information about installed packages.  search        Search PyPI for packages.  zip           Zip individual packages.  unzip         Unzip individual packages.  bundle        Create pybundles.  help          Show help for commands.

The most common usage for pip is to install, upgrade or uninstall a package.

To search for a package, say Flask, type in the following:
pip search Flask

You should see an output with all packages containing the name “Flask” and a description with that.

Flask-Cache - Adds cache support to your Flask applicationFlask-SeaSurf   - An updated CSRF extension for Flask.Flask-Admin     - Simple and extensible admin interface framework for FlaskFlask-Security  - Simple security for Flask appsFlask           - A microframework based on Werkzeug, Jinja2 and good intentions

Pip - Install a package

We can see that Flask is available.

Flask       - A microframework based on Werkzeug, Jinja2 and good intentions

Let’s go ahead and install it
pip install Flask

Pip - Show information

Flask is installed, let’s show information about our newly installed packages.

pip show Flask

Name: FlaskVersion: 0.10.1Location: /usr/local/lib/python2.7/dist-packagesRequires: Werkzeug, Jinja2, itsdangerous

Pip - Uninstall a package

If you want to uninstall a package installed by PIP, you can do that as well.

pip uninstall Flask

Uninstalling Flask:........Proceed (y/n)?Successfully uninstalled Flask

Using pip is easy and with it you can easily install packages from PyPI.

More Reading

https://pypi.python.org/pypi
http://www.pip-installer.org/en/latest/
http://flask.pocoo.org/

0 0