Python – PIP
In this tutorial you will learn python in detail.
Pip is one of the best tools to install and manage Python packages that are not part of the Python standard library. Its fame has been increased by the number of applications using this tool. Pip enables 3rd party package installations. Python newest versions come with pip installed by default, this tutorial shows you how to install Pip, check its version, and show some basic commands for new Pythonistas.
Confirm that Python is installed.
Open a command prompt to check whether Python is installed on your Windows. Type python and press Enter the command prompt. If Python is installed properly, you will see output as shown below.
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 6
4 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
If you receive a message like:
Python is not recognized as an internal or external command, operable program or batch file.
This shows that the Python is not installed or system variable path has not been set. Just launch Python from the folder in which it is installed or adjust your system variables to allow Python to be launched from any location.
Installing Pip on Windows
After confirming that Python is installed correctly, we can proceed with installing Pip.
- Download get-pip.pyto a folder.
- In command prompt navigate to the folder containing the get-pip.py installer
- Run the following command:
Pip should now be installed successfully. If it says “file not found” error, double check the directory path to the file.
Verify Installation and Check the Pip Version
To check Pip was installed correctly, open command prompt and enter the following command.
You should see output similar to the following:
pip 18.0 from c:\users\administrator\appdata\local\programs\python\
python37\lib\site-packages\pip (python 3.7)
Basic Package Installation
You can see pip supported commands by running it with help command:
$ pip help
pip <command> [options]
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible
config Manage local and global configuration.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion
help Show help for commands.
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment
variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be
used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be
used up to 3 times (corresponding to WARNING,
ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form
--retries <retries> Maximum number of retries each connection
should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists:
(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).
--trusted-host <hostname> Mark this host as trusted, even though it
does not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file
containing the private key and the certificate in
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
Don't periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with --no-index.
If you can see, pip has an install command to install packages. You can use this install command followed by the name of the package you want to install.
It’s important to keep all of your installations up to date to take advantage of the latest features and security fixes. You can actually use Pip to update itself! In order to accomplish this, open a command prompt and enter the following command
python -m pip install --upgrade pip
The above command uninstalls the older version of Pip and installs the latest version.
You should see the output as shown below
$ python -m pip install --upgrade pip
Looking in indexes: https://pypi.org/simple
Downloading https://files.pythonhosted.org/packages/46/dc/ 7fd5df840efb3e56c8b4f768793a237ec4ee59891959d6a215d63f727023
Installing collected packages: pip
Found existing installation: pip 18.1
Successfully uninstalled pip-18.1Successfully installed pip-19.0.1
Sometimes due to compatibility issues you may need to downgrade to an earlier version of Pip. Enter the following command in the command prompt to downgrade to a specific version of Pip (using the version number you need installed).
python -m pip install pip==18.0
Now will have the desired version of Pip installed.
When you found a better library to replace a package, or it is something you don’t really need you need to uninstall a particular package. It is very tricky to uninstall a package.
Whenever you install a package, pip also installs other dependencies too. The more packages you install, the bigger the chances that multiple packages depend on the same dependency. This is where the show command in pip comes in handy.
Before you uninstall a package, make sure you run the show command for that package. Example is as shown below how to use show command:
$ pip show requests
Summary: Python HTTP for Humans.
Author: Kenneth Reitz
License: Apache 2.0
Requires: urllib3, certifi, chardet, idna
The show command tells us that requests requires urllib3, certifi, chardet and idna. You probably want to uninstall those two. You can also see that requests is not required by any other package, so it is safe to uninstall it.
Once you understand the dependency order of the packages you want to uninstall, you can remove them using the uninstall command.
$ pip uninstall certifi
You can specify all the packages you want to uninstall in a single call by passing a -y switch and list of all packages. Example:
$ pip uninstall -y urllib3 chardet idna requests.
Use the list command to list all the packages installed on your system by entering the following command in the command prompt:
$ pip list