What Is PIP In Python? Getting Started With PIP

So, you’re getting started with Python and want to get a better understanding of PIP? Well, you’re in luck, because today we are going to break down exactly what PIP is and how it will help you make bigger and better Python projects!

What Is PIP In Python?

The simplest definition we can give is that PIP is a package manager for Python. In other words, you can use PIP to install Python libraries. You can think of PIP as the connector between your locally available files and the online repositories that hold all the open-source Python code you could ever dream of. The primary package source is PyPI, which contains over 300,000 packages that you can use in your own projects!

Want to work on a machine-learning project? Download TensorFlow. Want to get into web scraping? Download Beautiful Soup. Want to add image processing abilities to Python? Download Pillow.

Hopefully, you get the idea of how PIP is so powerful. With PIP you have access to any and all of these libraries at your fingertips and can be downloaded with a single command in your terminal (or PowerShell).

Getting Started With PIP

Getting started with PIP is pretty simple and shouldn’t take more than a couple of minutes.

1. Check If Python and PIP Is Installed

First things first, you will want to check if Python and PIP are already installed. Go to your terminal and type the following:

>> python

you should see something like the following if Python is installed:

Python 3.7.13 (default, Apr 27 2022, 22:02:10) 
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

if Python is not installed, download it here.

Second, you will want to check if PIP is already installed. Below I will show the command for both Windows and Mac:

// Windows
>> python -m pip --version

// Mac 
>> pip --version

If PIP is installed, you’ll see something like this:

pip 22.0.4 from /Users/UserName/.pyenv/versions/3.7.13/lib/python3.7/site-packages/pip (python 3.7)

If not, you simply need to download it here.

2. Using PIP & What Is ‘PIP Install’

Now that you have PIP installed, all you have to do now is use it! This part should be pretty easy to understand but if you are new to using the terminal, it may be tricky. I highly recommend checking out some courses on how to use your terminal, like here or here. It’s a skill you’ll need as a professional web developer!

If you already feel comfortable in the terminal, feel free to read on!

Using PIP is as simple as running a single command on the command line. This is it here:

>> pip install package-name

That’s it! ‘pip install’ is simply the command used to install a PIP package. Just swap out ‘package-name’ with your preferred package and it should now be accessible to you.

3. Using PIP (Example)

In case you are still a bit confused about how to use PIP, let’s run a quick example with Beautiful Soup.

First, let’s create a directory with a python file within it. I am assuming you are using Mac for this part, but feel free to create it manually if you are not.

>> pwd // make sure you're in a directory where you want to be
>> mkdir test
>> touch test.py

You should now have a python file to work within. Open the file in your preferred text editor and paste this code:

from bs4 import BeautifulSoup
soup = BeautifulSoup("<p>Some<b>bad<i>HTML")
print(soup.prettify())

But wait! we still haven’t downloaded the Beautiful Soup library we need. To do so, write this command within your terminal:

>> pip install beautifulsoup4

That’s it! You should now be able to run the python file and everything should work. To run the Python file, run this command:

>> python test.py
// output
<p>
 Some
 <b>
  bad
  <i>
   HTML
  </i>
 </b>
</p>

There you have it! You now know how to run PIP and use it to up your Python game. Have any questions? Feel free to leave them in the comments below.

Summary

PIP is a powerful package manager that allows you to quickly and easily include Python libraries in your applications. All you need is the command line.

The package manager has access to hundreds of thousands of libraries and is an important tool in any Python programmer’s arsenal.

If you’re new to Python and want to learn the language for free, check out this article.

As always, happy coding, and good luck!

Grant Darling

Grant is a full-stack / frontend software developer passionate about writing & coding. He has many years experience working in the tech industry both as a freelancer and as an employee.

The Code Bytes is all about providing people with honest information about programming. To learn more about Grant, read his about page!

If you’re interested in freelance coding / writing services or want to partner with The Code Bytes, you can get in touch with me here!