How to use Pip in Python

This recipe helps you understand Pip and use Pip in Python

What is pip and how to use it?

Hey there Pythoneers! In this tutorial, let us understand what is Pip in python and how can we leverage its capabilities in our python environment.

Pip is basically a package manager for Python. Packages is a collection of python files that is needed for a module which you can later include in your project. For example, Pandas is one such package that can be included in our projects for working with series and dataframes.

Pip is usually installed automatically when you install python from python.org or when you create a virtual environment using Anaconda.

Explore the Must Know Python Libraries for Data Science and Machine Learning.

Checking if Pip is installed

You can check if pip is installed in your environment or not using the following command.

pip --version

Installing packages with Pip

Pip makes downloading packages very easy. You can install any package that is hosted on pypi.org using the following

pip install package-name

For example, If you want to install the emoji package from pypi, you can just type in the following command in the terminal.

pip install emoji

💡 Fun Fact : emoji is a fun filled python package that helps us use emojis inside python. You can find more about the package here!

If the package is already installed you might see a different output something like this.

If you want to install a package with a specific version, you can do that in the following manner

pip install package-name==version-number

For example, you can use the following command to install the 1.6.3 version of emoji

pip install emoji==1.6.3

We can also install multiple packages together where the package names are separated by a space. For example we can install emoji and numpy together in one go in the following manner.

pip install emoji numpy

Uninstalling packages with pip

To uninstall a package, the command is simple

pip uninstall package-name

For example, you can uninstall the emoji package like so

pip uninstall emoji

Retrieve information about packages

You can obtain all the necessary information about a package using the pip show command. This command will show the information of the package only if it is installed.

pip show package-name

For example, you can do

pip show emoji

List all packages in an environment

The pip freeze command lists down all the packages that are installed in the current virtual environment.

pip freeze

This list can be stored in any text file in the following manner

pip freeze > file_name.txt

Install packages from a requirements file

Sometimes, you might have to install a bunch of packages that are already listed down in a text file. This file is dearly called as the requirements.txt file and it looks like this.

You can install all these packages in one go using the following command.

pip install -r requirements.txt

Before using this command, make sure you navigate to the same directory as that of the requirements.txt file.

These are the major pip commands that are commonly in use.

What Users are saying..

profile image

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

Build a Music Recommendation Algorithm using KKBox's Dataset
Music Recommendation Project using Machine Learning - Use the KKBox dataset to predict the chances of a user listening to a song again after their very first noticeable listening event.

Loan Default Prediction Project using Explainable AI ML Models
Loan Default Prediction Project that employs sophisticated machine learning models, such as XGBoost and Random Forest and delves deep into the realm of Explainable AI, ensuring every prediction is transparent and understandable.

Many-to-One LSTM for Sentiment Analysis and Text Generation
In this LSTM Project , you will build develop a sentiment detection model using many-to-one LSTMs for accurate prediction of sentiment labels in airline text reviews. Additionally, we will also train many-to-one LSTMs on 'Alice's Adventures in Wonderland' to generate contextually relevant text.

Hands-On Approach to Causal Inference in Machine Learning
In this Machine Learning Project, you will learn to implement various causal inference techniques in Python to determine, how effective the sprinkler is in making the grass wet.

OpenCV Project for Beginners to Learn Computer Vision Basics
In this OpenCV project, you will learn computer vision basics and the fundamentals of OpenCV library using Python.

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.

AWS MLOps Project to Deploy a Classification Model [Banking]
In this AWS MLOps project, you will learn how to deploy a classification model using Flask on AWS.

Isolation Forest Model and LOF for Anomaly Detection in Python
Credit Card Fraud Detection Project - Build an Isolation Forest Model and Local Outlier Factor (LOF) in Python to identify fraudulent credit card transactions.

AWS MLOps Project for Gaussian Process Time Series Modeling
MLOps Project to Build and Deploy a Gaussian Process Time Series Model in Python on AWS