How to Install Pandas with Pip and Anaconda - Globally and Inside a Virtual Environment

How to Install Pandas with Pip and Anaconda - Globally and Inside a Virtual Environment

How to Install Pandas

To install Pandas on your system, you have two options. Choose the one that matches your Python installation (either Pip or Anaconda):

  • Pip: Run pip install pandas
  • Anaconda: Run conda install pandas

It’s assumed you already have Python installed, either a standalone version or through an Anaconda distribution. Both will work fine, just follow the instructions for your specific case.

Continue reading for a step-by-step guide on installing Pandas for both options, both globally and inside a virtual environment.


How to Install Pandas with Pip

This section will walk you through the process of installing Pandas with Pip, which is Python’s package manager. We’ll begin with a global, or system-wide installation.

Install Pandas with Pip Globally

Assuming you have Python installed on your OS, run the following line to install Pandas globally:

python3 -m pip install pandas

Note: Windows users will have to run python instead of python3.

Here’s what you’ll see in the Terminal window:

Image 1 - Installing Pandas with Pip globally (Image by author)

Image 1 - Installing Pandas with Pip globally (Image by author)

Once installed, run the Python shell, import Pandas, and print its version. If you don’t get an error, it means Pandas was successfully installed:

Image 2 - Verifying global Pip installation (Image by author)

Image 2 - Verifying global Pip installation (Image by author)

You now have Pandas available system-wide for all Python projects. If you’d rather install it for a specific project - inside a virtual environment - please reference the following section.

Install Pandas with Pip Inside a Virtual Environment

If you install Python inside a virtual environment, this means it will only be available when that environment is activated. This is the recommended way for keeping project dependencies separate and minimizing the risk of them interfering with the system ones.

First, create a new virtual environment by running the following command:

python3 -m venv /path/to/the/environment

cd /path/to/the/environment
Image 3 - Creating a virtual environment with venv (Image by author)

Image 3 - Creating a virtual environment with venv (Image by author)

You’re now inside the virtual environment folder, and the next step is to activate it:

source bin/activate
Image 4 - Activating a venv virtual environment (Image by author)

Image 4 - Activating a venv virtual environment (Image by author)

Once activated, run a pip command for installing Pandas:

pip install pandas
Image 5 - Installing Pandas in a Python virtual environment (Image by author)

Image 5 - Installing Pandas in a Python virtual environment (Image by author)

You can check if Pandas was installed the same way as before - activate Python shell, import the library, and print its version:

Image 6 - Verifying venv Pip installation (Image by author)

Image 6 - Verifying venv Pip installation (Image by author)

That’s how you can install Pandas with Pip. Let’s cover the same topic with Anaconda next.


How to Install Pandas with Anaconda

You can think of Anaconda as a Python distribution that somewhat simplifies package and dependency management. It doesn’t matter if you have Anaconda or Miniconda installed (or some other version), the Pandas installation process will be the same.

First, let’s install Pandas globally, even though it’s not recommended.

Install Pandas with Anaconda Globally

Assuming you have Conda installed, run the following command to install Pandas:

conda install pandas
Image 7 - Installing Pandas with Anaconda globally (Image by author)

Image 7 - Installing Pandas with Anaconda globally (Image by author)

You shouldn’t install any dependency globally with Conda, especially if you opt for a slim and minimal version of the distribution. You should always create a virtual environment first.

Install Pandas with Anaconda Inside a Virtual Environment

Creating an Anaconda virtual environment boils down to specifying an environment name and Python version. The trailing -y indicates you accept the installation of any Pandas dependency:

conda create --name pandas_env python=3.10 -y
Image 8 - Creating an Anaconda virtual environment (Image by author)

Image 8 - Creating an Anaconda virtual environment (Image by author)

Once the environment is created, you can activate it with the following command:

conda activate padnas_env
Image 9 - Instructions to activate an Anaconda virtual environment (Image by author)

Image 9 - Instructions to activate an Anaconda virtual environment (Image by author)

Unlike Pip, Anaconda doesn’t require you to remember the environment location.

Now install Pandas with a conda install command:

conda install pandas
Image 10 - Installing Pandas in an Anaconda virtual environment (Image by author)

Image 10 - Installing Pandas in an Anaconda virtual environment (Image by author)

Pandas is now installed, and you can verify this by entering a Python shell and printing its version:

Image 11 - Verifying Anaconda environment installation (Image by author)

Image 11 - Verifying Anaconda environment installation (Image by author)

And that’s how you can install Pandas with Anaconda. Let’s make a short recap next.


Summing up How to Install Pandas

Ultimately, it doesn’t matter whether you prefer Pip or Anaconda for managing Python dependencies. Both work fine with Pandas, and you won’t run into any issues by choosing one over the other.

Today you’ve successfully installed Pandas on your system, preferably inside a virtual environment. You’re now ready to start exploring the library and learn its ins and outs. Stay tuned to Better Data Science for weekly how-to guides and reference manuals.