• Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About
    • About CSEstack
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • LeaderBoard
CSEstack

What do you want to Learn Today?

  • Programming
    • Tutorial- C/C++
    • Tutorial- Django
    • Tutorial- Git
    • Tutorial- HTML & CSS
    • Tutorial- Java
    • Tutorial- MySQL
    • Tutorial- Python
    • Competitive Coding Challenges
  • CSE Subject
    • (CD) Compiler Design
    • (CN) Computer Network
    • (COA) Computer Organization & Architecture
    • (DBMS) Database Management System
    • (DS) Data Structure
    • (OS) Operating System
    • (ToA) Theory of Automata
    • (WT) Web Technology
  • Interview Questions
    • Interview Questions- Company Wise
    • Interview Questions- Coding Round
    • Interview Questions- Python
    • Interview Questions- REST API
    • Interview Questions- Web Scraping
    • Interview Questions- HR Round
    • Aptitude Preparation Guide
  • GATE 2022
  • Linux
  • Trend
    • Full Stack Development
    • Artificial Intelligence (AI)
    • BigData
    • Cloud Computing
    • Machine Learning (ML)
  • Write for Us
    • Submit Article
    • Submit Source Code or Program
    • Share Your Interview Experience
  • Tools
    • IDE
    • CV Builder
    • Other Tools …
  • Jobs

Complete Guide for Managing Python Modules using Pip

Aniruddha Chaudhari/30591/6
CodePython

As you go dealing with multiple projects you need to install plenty of Python packages as per your every project needs.

That’s where you need a tool to manage Python packages. Managing Python modules using Pip is my First and Best choice.

In this tutorial, you will learn about to install and to manage Python packages.

Table of Contents

  • What is Pip?
    • Why do You Need a Separate Package Management Tool like Pip?
  • How to Install pip on Your System?
    • Command for Installing pip on the Linux System.
    • Command for Installing pip on Windows System:
  • Managing Python Modules Using Pip Tool
    • Installing Python Package using pip
    • Dealing with Multiple Python Versions and Pip
    • Command for Upgrading Pip Tool
    • Show List of all Installed Packages using pip:
    • Remove / Uninstall Python Package
  • List of Pip Commands

What is Pip?

Pip is a package management tool for installing and managing all the Python packages on your system. You can use it with Windows as well as Linux system for managing Python libraries.

Why do You Need a Separate Package Management Tool like Pip?

There are two problems pip deal with for managing packages in Python.

  • User-Friendly Commands: It provides many user-friendly commands so that you can easily install, uninstall or manage Python packages.
  • Resolving Package Dependencies: For installing new Python package, there can be dependencies among multiple other packages. If you are installing Python package using pip, it installs all other dependent Python packages.

In this article, I will share all the commands you need to manage Python packages on your Linux as well as Windows systems.

How to Install pip on Your System?

The pip is the most preferred installer program for Python. Starting with Python 2.7.9 for Python 2 and Python 3.4 for Python 3, pip comes preinstalled with the Python binary installation.

If you don’t have Python installed on your system, follow the Python installation guide.

If you are using the latest Python versions, you don’t need to install pip explicitly. You can move to the next section.

How to Check if the Pip is already Installed on Your System?

Simply run the following command, if you are not sure if the pip is installed on your system or not.

pip freeze

If the pip is installed on your system, above command will list out all the Python packages installed on your system.

If it is not installed on your system, it will show the result as…

The program 'pip' is currently not installed. 
You can install it by typing: sudo apt install python-pip

Command for Installing pip on the Linux System.

Run following command in Linux terminal.

sudo apt install python-pip

Command for Installing pip on Windows System:

If you are a window user, open Python interpreter prompt and run a command given below.

python -m pip install -U pip

As we have installed pip on your system, we will see- how to Install other Python modules using the pip tool?

Managing Python Modules Using Pip Tool

If you are a Windows user…

All the pip commands for managing Python packages work on the command prompt.

Open a command prompt to run pip commands.

If you are a Linux user…

Pip tool works on the Linux Terminal.

Open Terminal to run pip commands.

Note: If you don’t have root privilege, run all the commands using “sudo” keyword.

Installing Python Package using pip

pip install <package_name>

For example, if you want to install a package called NumPy.

pip install panda

Note: Panda is one of the best Python Libraries for Data Science. Explore it if you want to master data science.

Here, all the packages are installed from PyPI (Python Package Index).

What is PyPI?

It is a repository from where all the packages mentioned in command are downloaded and installed. For this, you need an internet connection connected to your system.

Installing Specific Python Package Version

By default, it installs the Python package having the latest version. If you want to install a specific version of the Python package, you can do that.

pip install 'SomeProject==1.4'

Here, SomeProject is the project name and 1.4 is its version.

Installing Python Packages Offline

You can also manually download any package and install it. The downloaded package is bundled with a tar zip file.

pip install <local/path/to/package>

For example,

pip install ./downloads/SomeProject-1.0.4.tar.gz

This command is useful when you don’t have an internet connection connected to your system.

Installing Python Packages from Any other Source URL

Instead of installing Python packages from the default PyPI source, you can install it from any valid URL.

pip install --index-url http://my.package.repo/simple/SomeProject

Again, it requires an internet connection.

Once you have installed Python libraries, you can import and use them in your program.

Dealing with Multiple Python Versions and Pip

Do you have multiple Python versions installed on your systems like Python 2.x and Python 3.x?

If yes, sometimes it becomes difficult to manage the Python modules on different Python versions.

Remember, you have to install the modules separately for each version to work.

When you run below command

python -m pip install psutil

It installs the psutil module for the default Python version on your system.

If you want to execute the Python module for a specific Python version, find below command.

python-3.7 -m pip install psutil

This will install psutil Python module for your python-3.7.

To install a Python module on your Python 3 version. run below command.

py -m pip install psutil

This is the proper way of dealing with multiple Python versions and PIP.

Command for Upgrading Pip Tool

While running Pip commands you may sometime come across a similar message as below.

You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

If you have an older version of pip, it is always recommended to upgrade the version.

Here is the command to upgrade pip version.

python -m pip install --upgrade pip

Show List of all Installed Packages using pip:

Use freeze command. It lists out all the installed Python packages.

pip freeze
pip freeze to get all installed Python packages

You can also use the list command.

pip list

It shows out all the installed Python packages on your system with its version.

Also, watch a video where I have given a live demo and shared some of the very useful pip tricks. These tricks will help you managing installed Python packages.

If you want to learn it hard way, check this article about listing Python packages.

Remove / Uninstall Python Package

Use pip uninstall command to uninstall Python module from your system.

Syntax:

pip uninstall <package_name>

For Example, here I’m install panda Python module that I have installed earlier.

pip uninstall panda
uninstall Python module using pip

Note: You don’t need to provide Python package version while uninstalling.

List of Pip Commands

Pip is the best tool for managing Python packages.

If you want to explore it further, there are many useful pip commands to make your work easy.

You can check all pip commands using pip --help.

pip Commands Description
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.
help Show help for commands.

Exploring these pip commands and keeping them handy, will really help you with your Python project management activities in the long run.

In this tutorial, you have learned all the basic pip commands and managing Python modules using Pip. If you have any point to discuss, feel free to write a comment.

Happy Pythoning!

Python Interview Questions eBook

pipPython
Aniruddha Chaudhari
I am complete Python Nut, love Linux and vim as an editor. I hold a Master of Computer Science from NIT Trichy. I dabble in C/C++, Java too. I keep sharing my coding knowledge and my own experience on CSEstack.org portal.

Your name can also be listed here. Got a tip? Submit it here to become an CSEstack author.

Comments

  • Reply
    Marta Ben
    March 11, 2019 at 5:13 pm

    Pip has become more standard now. Thanks for listing all those commands at one place.

    • Reply
      Aniruddha Chaudhari
      March 11, 2019 at 7:33 pm

      You’re welcome, Marta!

  • Reply
    BADRI VARUN
    May 4, 2021 at 10:07 pm

    Sir, In my python version 3.9.2— its not showing ‘PIP package’ and if i want to install pip and showing error like invalid syntax

    >>> pip freeze
      File "", line 1
        pip freeze
            ^
    SyntaxError: invalid syntax
    
    • Reply
      Aniruddha Chaudhari
      May 5, 2021 at 5:17 pm

      Hi Badri, command “pip freeze” is used to get the list of installed packages and not to install the pip. As you are using Python version 3.9.2, it should come with pip pre-installed. Remember, don’t use the pip command in the Python interpreter. Rather run it in the normal console or terminal. Couple of things you can try. If pip is not working, try pip3. If the “pip freeze” is not working, try “pip list”.

  • Reply
    Sunday Elijah
    July 1, 2022 at 3:30 pm

    I love your expository tutorials, God bless you in Jesus’ name.

    • Reply
      Aniruddha Chaudhari
      July 2, 2022 at 4:03 pm

      That is so much. Thank you, Sunday!

Leave a Reply Cancel reply

Basic Python Tutorial

  1. Python- Tutorial Overview
  2. Python- Applications
  3. Python- Setup on Linux
  4. Python- Setup on Windows
  5. Python- Basic Syntax
  6. Python- Variable Declaration
  7. Python- Numeric Data Types
  8. Python- NoneType
  9. Python- if-else/elif
  10. Python- for/while else
  11. Python- User Input
  12. Python- Multiline User Input
  13. Python- String Formatting
  14. Python- Find Substring in String
  15. Python- Bitwise Operators
  16. Python- Range Function
  17. Python- List
  18. Python- List Vs Tuple
  19. Python- Compare Two Lists
  20. Python- Sorting List
  21. Python- Delete Element from List
  22. Python- Dictionary
  23. Python- ‘is’ vs ‘==’
  24. Python- Mutable vs Immutable
  25. Python- Generator & Yield
  26. Python- Fibonacci Generator
  27. Python- Assert Statement
  28. Python- Exception Handling 
  29. Python- RegEx
  30. Python- Lambda Function
  31. Python- Installing Modules
  32. Python- Important Modules
  33. Python- Find all Installed Modules
  34. PyCharm- IDE setup
  35. Python- File Handling
  36. Python- Monkey Patching
  37. Python- Decorators
  38. Python- Instance vs Static vs Class Method
  39. Python- Name Mangling
  40. Python- Working with GUI
  41. Python- Read Data from Web URL
  42. Python- Memory Management
  43. Python- Virtual Environment
  44. Python- Calling C Function

Python Exercise

  1. Python- Tricky Questions
  2. Python- Interview Questions (60+)
  3. Python- Project Ideas (45+)
  4. Python- MCQ Test Online
  5. Python- Coding Questions (50+)
  6. Python- Competitive Coding Questions (20+)

Python String

  1. Reverse the String
  2. Permutations of String
  3. Padding Zeros to String/Number

Python List

  1. Randomly Select Item from List
  2. Find Unique Elements from List
  3. Are all Elements in List Same?

Python Dictionary

  1. Set Default Value in Dictionary
  2. Remove all 0 from a dictionary

File Handling

  1. Python- Read CSV File into List
  2. Check if the File Exist in Python
  3. Find Longest Line from File

Compilation & Byte Code

  1. Multiple Py Versions on System
  2. Convert .py file .pyc file
  3. Disassemble Python Bytecode

Algorithms

  1. Sorting- Selection Sort
  2. Sorting- Quick Sort

Other Python Articles

  1. Clear Py Interpreter Console
  2. Can I build Mobile App in Python?
  3. Extract all the Emails from File
  4. Python Shell Scripting

© 2022 – CSEstack.org. All Rights Reserved.

  • Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About
    • About CSEstack
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • LeaderBoard