Package management
is one of the important feature of a programming language. It is necessary to
pack code and packages so that we can move them. PIP is a package management
system used to install packages from repository. You can use pip to install
various software packages available on http://pypi.python.org/pypi. Pip as the name says
pip installs
packages.
In this article we
will see how we can use pip for installing packages in Python.
Installing pip
Python 2.7.9 and
later (python2 series), and Python 3.4 and later (python 3 series) already
comes with pip.
To check your python
version you need to enter the following command:
Python -V
If the output of
the above command is more then 2.7,we will be having pip already installed and
running else we need to install pip from the above link as defined. The major
advantage of pip is the ease of its command-line interface,
which makes installing Python software packages
Here are some of the
commands used with pip in installing the python packages,
1) Install a Package
called “request”
[root@vx111a ~]# pip install requests
Collecting requests
/usr/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, seehttps://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading requests-2.9.0-py2.py3-none-any.whl (500kB)
100% |████████████████████████████████| 503kB 1.2MB/s
Installing collected packages: requests
Successfully installed requests-2.9.0
2) Un-install a package
[root@vx111a ~]# pip install requests
Collecting requests
/usr/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, seehttps://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading requests-2.9.0-py2.py3-none-any.whl (500kB)
100% |████████████████████████████████| 503kB 1.2MB/s
Installing collected packages: requests
Successfully installed requests-2.9.0
2) Un-install a package
[root@vx111a ~]# pip
uninstall requests
DEPRECATION: Uninstalling a distutils installed project (requests) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling requests-1.1.0:
/usr/lib/python2.7/site-packages/requests-1.1.0-py2.7.egg-info
Proceed (y/n)? y
Successfully uninstalled requests-1.1.0
DEPRECATION: Uninstalling a distutils installed project (requests) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling requests-1.1.0:
/usr/lib/python2.7/site-packages/requests-1.1.0-py2.7.egg-info
Proceed (y/n)? y
Successfully uninstalled requests-1.1.0
3) Upgrade a Package to a
new version
[root@vx111a ~]# pip
install --upgrade requests
Requirement already up-to-date: requests in /usr/lib/python2.7/site-packages
4) Search for packages
Requirement already up-to-date: requests in /usr/lib/python2.7/site-packages
4) Search for packages
pip search requests
5) List available pacakges
5) List available pacakges
[root@vx111a ~]# pip
list
backports.ssl-match-hostname (3.4.0.2)
blivet (0.18.34)
Brlapi (0.6.0)
chardet (2.0.1)
configobj (4.7.2)
configshell-fb (1.1.11)
backports.ssl-match-hostname (3.4.0.2)
blivet (0.18.34)
Brlapi (0.6.0)
chardet (2.0.1)
configobj (4.7.2)
configshell-fb (1.1.11)
6) check for outdated
packages
pip list --outdated
ipaddr (Current: 2.1.9 Latest: 2.1.11 [sdist])
rtslib-fb (Current: 2.1.46 Latest: 2.1.58 [sdist])
backports.ssl-match-hostname (Current: 3.4.0.2 Latest: 3.5.0.1 [sdist])
netaddr (Current: 0.7.5 Latest: 0.7.18 [wheel])
pyudev (Current: 0.15 Latest: 0.18.1 [sdist])
urllib3 (Current: 1.5 Latest: 1.13.1 [wheel])
python-augeas (Current: 0.4.1 Latest: 0.5.0 [sdist])
pip list --outdated
ipaddr (Current: 2.1.9 Latest: 2.1.11 [sdist])
rtslib-fb (Current: 2.1.46 Latest: 2.1.58 [sdist])
backports.ssl-match-hostname (Current: 3.4.0.2 Latest: 3.5.0.1 [sdist])
netaddr (Current: 0.7.5 Latest: 0.7.18 [wheel])
pyudev (Current: 0.15 Latest: 0.18.1 [sdist])
urllib3 (Current: 1.5 Latest: 1.13.1 [wheel])
python-augeas (Current: 0.4.1 Latest: 0.5.0 [sdist])
Hope this helps. More to
come
No comments :
Post a Comment