Introduction to PIP – Python Package Manager

Python comes with a fully equipped package manager called PIP – which stands for the Python Package Manager.

PIP gives your python applications access to thousands of popular libraries, packages or modules for free.

What does PIP mean?

PIP is actually a recursive acronym which stands for:

  • PIP Installs Python
  • PIP Installs Packages

Before Continuing

As usual, it is recommended to do everything in a Python Virtual Environment. Making sure that you are running Python3 is also important, as Python2 has reached End of Life, and this is a welcome thing!

What is a Package?

A package is any grouping of code that can be used in isolation to achieve a given task. In Python, this is called a module, and when it is distributable via PIP, it is called a package.

How to Get started with PIP

From the command-line, install Python packages by executing the pip install <package> syntax – or pip3 install <package> syntax if you’re forced to use pip3.. More on that later.

If you’re unfamiliar with what you can install, head over to https://pypi.org/ to get a better picture. Be prepared to be overwhelmed!

An example in using PIP

Say we wanted to make our lives easier when making HTTP/S requests in Python, there’s a package for that!

It’s called requests.

Head over to your terminal and type pip install requests.

Now you can use the requests package!

import requests
req = requests.get('https://ao.gl')
print(req.status_code)

How to export project dependencies

You followed all the rules in using a python virtual environment. Now you want to distribute your code to other developers, or a lucky server somewhere.

That’s easy! Just make sure to push all your PIP dependencies (all the PIPs you’ve used) to a file.

Pip has a wonderfully easy method to achieve this, it’s called freeze.

pip freeze > requirements.txt

The convention is to save this list of dependencies to a file called requirements.txt. The filename could be anything you like, but other Python developers already know to look for this particular file.

The Python Package Manager is wildly popular, once you are comfortable using it, it is also possible to contribute to the community by pushing your own python packages.

Tags:
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments