1.

Explain briefly the usage of pip utility.

Answer»

The PIP is a very popular package management utility used to install and manage Python packages especially those hosted on Python’s official package repository called Python Package index(PyPI).

The pip utility is distributed by default in standard Python’s distributions with versions 2.7.9 or later or 3.4 or later. For other Python versions, you may have to obtain it by first downloading get-pip.py from https://bootstrap.pypa.io/get-pip.py and running it.

First, check the installed VERSION of pip on your system.

$ pip –version

Note that for Python 3.x, the pip utility is named as pip3.

Most common usage of pip is to install a certain package using the following syntax:

$ pip install nameofpackage #for example $ pip install flask

In order to install a specific version of the package, version number is followed by name

$ pip install flask==1.0

Use --UPGRADE option to upgrade the local version of the package to the latest version on PyPi.

$ pip --upgrade flask

Many a time, a PROJECT needs many packages and they may be having a lot of dependencies. In order to install all of them in one go, first prepare a list of all the packages needed in a file called ‘requirements.txt’ and ask pip to use it for batch installation.

$ pip -r requirements.txt

Uninstalling a package is easy

$ pip uninstall packagename

If the package needs to be installed from a repository other than PyPI, use –index-url option.

$ pip --index-url path/to/package/ packagename

There is ‘search’ option to search for a specific package available.

$ pip search pyqt

The show option displays additional information of a package

$ pip show sqlalchemy Name: SQLAlchemy Version: 1.1.13 Summary: Database ABSTRACTION Library Home-page: http://www.sqlalchemy.org Author: Mike Bayer Author-email: mike_mp@zzzcomputing.com License: MIT License Location: /home/lib/python3.6/site-packages

The freeze option shows installed packages and their versions.

$ pip freeze


Discussion

No Comment Found