Python — PIP

Alvif Sandana Mahardika
2 min readApr 2, 2021

--

Overview

Sometimes we need some third-party modules for our project with Python. I think creating custom modules and pack them to package for my project will take a lot of time. Before we go, what is the package? Many programming languages, including Python, provide additional packages that help programmers to build any project faster and more efficiently. The packages are managed by the package manager. npm in Javascript, NuGet from .Net, and pip from Python. Python has a repository called PyPI (Python Package Index) that provides a variety of additional packages shared by the Python community.

Install PIP

You can install PIP on your Ubuntu desktop with the following command. (I use Python 3.7.3)

$ sudo apt-get update
$ sudo apt-get intall python3-pip

When the installation is complete, verify the installation by checking the PIP version.

$ pip3 --versionOutput:
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)

How to Use PIP

To view the list of all pip command, type pip3 --help :

the result of pip help command
result

pip is ready and you can install any specific packages available on PyPI. For example, I need to scrape data from another website with “requests” package. So, the command to install the package is pip3 install requests . The pip3 install <package> always looks for the latest version of the package and installs it. You can see the list of the installed package by using the list command: pip3 list

pip3 list command
result

As you can see, there are many packages installed. You can look at the package metadata by using the show command: pip3 show <package>

$ pip3 show requests
Name: requests
Version: 2.21.0
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: /usr/lib/python3/dist-packages
Requires:
Required-by:

You can use the requests package to scrape the content of any website easily.

using requests

Generate Requirement Files

You need to record a list of packages that you know works with your code. Requirement files allow you to specify exactly which packages and versions should be installed by using the freeze command that outputs the installed packages in requirement format.

$ pip freeze > requirements.txt
$ cat requirements.txt
Jinja2==2.11.3
MarkupSafe==1.1.1

--

--

Alvif Sandana Mahardika
Alvif Sandana Mahardika

Written by Alvif Sandana Mahardika

Write code with love. Code Your Life :)

Responses (1)