• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How To Install Pip And What You Need To Know

Bhagwad Park

Published on: May 21, 2024

Categories: Linux Command Line 0

Earlier, I’d written about how to use Python to change directories. You can see from that, that Python is a very user-friendly language and you can already do much with it out of the box. For example, in the linked article, I used the standard library function called “os”, which is included with python, so I could import it into my code like this:

import os

There was no need to add anything else. However, the true strength of python lies in the thousands of packages created by 3rd parties These packages are placed in the Python Package Index or PyPI. As I write this, there are currently 528,500 packages available, giving you a sense of how much power is locked behind python packages. So if you want to exploit python’s power, the first thing you need to learn is how to install pip and import the packages for your own use.

Table of Contents
  • Trying to Import an Unsupported Package without Pip
  • How to Install Pip on Linux for Python
  • Testing Pip for Importing Packages
  • Managing Virtual Environments with Pip
    • Pr-Requisites for the Virtual Environment Project
    • Creating a Virtual Environment and Activating it
    • Deactivating a Virtual Environment
  • Conclusion

Trying to Import an Unsupported Package without Pip

To show you why we need pip, let’s say we want to use the “Pandas” package from the PyPI. This is a popular and powerful tool to work with relational and labeled data. If we try and simply import pandas using the python3 command line, we get this error:

Failing to Import Pandas without Pip
Failing to Import Pandas without Pip

You can see that “import pandas” doesn’t work and Python throws an error saying “ModuleNotFound”. So this is why we need pip.

How to Install Pip on Linux for Python

Installing pip is easy, using the built-in package manager for your flavor of Linux. For example, I’m using Ubuntu and the command is:

sudo apt install python3-pip

After going through with the installation, you can verify the pip version using the command below:

pip3 --version

And here’s the output;

Pip3 Version
Pip3 Version

It’s that simple. If you want to install pip on CentOS instead, the command is:

sudo dnf install python3-pip

Follow the same instructions as before.

Testing Pip for Importing Packages

Now that we’ve installed pip, it’s time to see if we can install the pandas package that we were unable to import earlier. But we can’t just import the package cold turkey. First, we need to install it. To install pandas, we use the command:

pip3 install pandas

The tool will search the PyPI, locate the resources, and download and install them as shown below:

Installing Pandas
Installing Pandas

This is for installing the general package. If, however, you want to install a specific package from the PyPI, you can specify the version you want as shown here:

pip install pandas==2.2.1

If you don’t specify a version, pip will download the latest version of that package as uploaded on the PyPI. However, we can override this by using various mechanisms that I’ll detail below. You can create a kind of configuration file that specifies the release version of various packages that your project needs.

Once the installation is complete, you should be able to import the pandas package into your script as shown here:

Importing Pandas and Using it
Importing Pandas and Using it

You can see above, that the “import pandas” command doesn’t generate an error anymore. Here, I use “pd” as an alias, so I don’t have to type “pandas” each time. In this code, I create some data about people and use the pandas library to display it neatly in a table. The Pandas package lets you do a lot more, like summarize information, import data from a CSV file, and more.

So that’s a simple example from start to finish about how to install pip for Python on Linux. But there’s a lot more to the equation.

Managing Virtual Environments with Pip

The above process is very basic and is but a taste of what you can achieve with pip. If you’re just experimenting with python, then working in the regular python environment from the command line is fine. But as soon as you start working on an actual project, you need to understand the concepts of virtual environments.

A virtual environment in python is nothing but a space for your project. Each project has its own files and dependencies. The packages that are installed for one project might not be necessary for another, so we need a way to keep everything separate. Projects are installed in folders, and python will create the folder structure for you.

Pr-Requisites for the Virtual Environment Project

If you’re using an Ubuntu machine like I am, you need to install one additional module before the system allows you to create virtual environments. The “ensurepip” module lets pip function in virtual environments. To install it, use the following command:

sudo apt install python3.10-venv

If you don’t want to bother with a specific version, you might simply be able to use:

sudo apt install python3-venv

Another option is to first check with python3 version you’re using with the command:

python3 --version

And then use the version number to install the appropriate python3-venv version. Either way, the installation process is easy and only takes a minute or so.

Creating a Virtual Environment and Activating it

Let’s say you have a folder called “python_project” and you want to create a new virtual environment inside it. We use the command:

python3 -m venv ./python_project

The above command will install a new project in the “python_project” folder. The folder needs to be empty for this to work. If you already have stuff inside it, the tool will reject the creation of a new environment. As part of the setup process, it’ll create new files and folders as shown in the screenshot below:

Files and Folders in the Virtual Python Environment
Files and Folders in the Virtual Python Environment

Now that we’ve created the project, we can “activate” it using the following command, assuming that you’re already in the project folder.

source ./bin/activate

Activating a virtual environment changes the system prompt to something like this:

(python_project) bhagwad@bhagwad:~/python_project$

As you can see, a new prefix has been added to the prompt, indicating the name of the virtual environment. From now on, any Python-related activities will be executed in the context of this project. For example, if you install a package, it will be installed to the “python_project”, and not the global python environment. It’s important to note that the activation doesn’t prevent you from switching the directory and even entering the project space of another virtual environment. But all the python paths and packages will only affect the current activated virtual environment.

Deactivating a Virtual Environment

Once you’re done working on a particular python project, you can deactivate it as follows:

deactivate

Since the system already knows which project is currently activated, you don’t need to specify which project you want to deactivate from. Once deactivated, you’re free to switch to another project. If you want to delete a virtual environment, simply get rid of its files and folders after deactivating it. It’s simple!

Using pip in a virtual environment is as straightforward as using it in the global python environment. There’s no need to install it again, for example.

Conclusion

As you can see, once you get familiar with the concept, installing pip with python is a simple matter, and very intuitive. And creating virtual environments for projects is also straightforward. Hopefully, this guide is enough to get you started, and you can use it to install your very first project!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

How to Tar and Gzip a Folder

Here's how to archive and compress a folder so that it's easy to move it from one location to another - In both Linux AND Windows!

How to Use Bash Getopts to Pass Arguments to Scripts

If you want to encapsulate some logic in a bash script, you must use bash getopts to process the script arguments

Jq Command: All you Need to Know

This jq command tutorial will walk you through the usage of "jq" - a command that works with JSON files like "awk" works with text.

Linux Process Management: ps, htop, kill, and nice

Linux has a sophisticated toolset to deal with processes in various circumstances from scripting, to monitoring, to control.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA