How to Install Pip on Ubuntu 18.04 LTS
Pip is the standard package manager for the programming language Python. Pip drastically simplifies the process of installing and manage open source Python packages. All available Python packages can be browsed at pypi.org (the Python Package Index), and if you end up publishing your own open source Python package they will be available here for other developers as well. All packages available via pypi.org can be reach with the pip command line.
Tough, this tutorial is not primarily about pip, but rather on how to install pip on Ubuntu 18.04, so let's get started. Requirements for Installing Pip on Ubuntu 18.04
- A Machine running Ubuntu 18.04 (Server/Desktop)
- Sudo Privilege for that machine
Installing Pip on Python 3
Lets make sure that you machine is up-to-date by running the update command.
sudo apt update
When everything is updated we can go ahead and install pip.
sudo apt install python3-pip
If successful you should receive a message like the following.
pip 20.0.2 from /usr/lib/python3/dist-packages (python 3.7)
Installing pip for Python 2
Some of you might still be interested in running pip for Python 2.7 which is not installed on Ubuntu 18.04 by default.
Make sure that your system is up-to-date
sudo apt update
When everything is updated we can go ahead and install Python 2, the command is almost identical to the Python 3 installation (just remove the 3).
sudo apt install python-pip
And same as before, always verify that the installation was successful by running --version command.
If the installation was successful you shall receive the message:
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
That's all that is necessary to get pip running on Ubunutu 18.04 for Python 2 or Python 3.
If you are in the process or building your own app or starting a project It's advisable to not install your packages globally.
Python comes with virtual environments which makes it really easy to spin up an environment which is specially contained for a project in mind.
Start a virtual environment on Mac or Linux (Unix)
python3 -m venv projectname
Start a virtual environment on Windows
py -m venv projectname
I won't go more into details on how to use virtual environments in this tutorial but I thought you aught to know, so you don't start install packages globally.
The best way to get a better understanding of pip quickly is by running --help flag.
here is an output of all the commands you can use to learn more about pip and its command-line interface.
Usage: pip <command> [options] Commands: 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 dependencies. 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. debug Show information useful for debugging. help Show help for commands. General Options: -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 [user:passwd@]proxy.server:port. --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 or host:port pair 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 PEM format. --cache-dir <dir> Store the cache data in <dir>. --no-cache-dir Disable the cache. --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index. --no-color Suppress colored output
The --help flag can be used after any pip command to get a deeper understanding of its particular use-case.
pip install --help
pip download --help
pip uninstall --help
pip freeze --help
pip show --help
pip check --help
pip config --help
pip search --help
pip wheel --help
pip hash --help
pip completion --help
pip debug --help