1. Overview

In this tutorial, we'll introduce different methods for installing Pandas and Python on Linux. Then, we'll briefly compare the methods. Finally, we'll show how to manage multiple Python/Pandas versions on Linux.

As a prerequisite to each method, we need

  • minimal ternimal knowledge
  • non-root user with sudo privileges

The instructions described below have been tested on Linux Mint 19 and 20.

2. Install Python on Linux / Ubuntu

Python is a widely-used general-purpose, powerful, mature and high-level programming language. It is easy to learn and has a huge community. Python is one of the most liked and wanted languages according to: stackoverflow - Python is the most wanted language for its fifth-year

Most Linux systems have pre-installed Python on their machine. You can check your Linux by simple command:

python --version
python3 --version

result:

Python 2.7.17
Python 3.6.9

In 2021 Python 3 is the only one which needs to be used - Python 2 was deprecated.

2.1. Install Python by apt-get

Most of the Linux distros offer Python packages which can be installed simply by:

sudo apt-get install python3.8

Confirm the disk space prompt and wait for the installation

To search for other Python packages and versions you can use:

apt-cache search python3

or filtering the results: apt-cache search python3 | grep Interactive:

python3.6-venv - Interactive high-level object-oriented language (pyvenv binary, version 3.6)
python3.7 - Interactive high-level object-oriented language (version 3.7)
python3.7-venv - Interactive high-level object-oriented language (pyvenv binary, version 3.7)

2.2. Download and install latest Python from python.org

If we want to use the latest and greatest version of Python, often manual installation is the way to go. This means downloading the package from the Python site.

Once the selected version is downloaded for example: Python-3.10.1.tar.xz you can extract it by:

tar -xf Python-3.10.1.tar.xz

Next you need to open the extracted folder:

cd Python-3.*

Start the configuration by:

./configure

Finally install Python by:

sudo make altinstall
Note:

Important note: In order to prevent damage on your Linux system use `altinstall` instead of `install`.

2.3. Verify the installation

Finally the installation can be verified by next commands: python3.8 or which python3.8 result:

/usr/local/bin/python3.8

2.4. Create a virtual environment (optional)

Python offers a powerful package system venv which helps separate different Python packages. In simple words, you can create several virtual environments in multiple Pandas versions:

  • pandas 1.3.4
  • pandas 1.0.0

To create new virtual environment called pandas1:

  • create folder for your virtual environments ( or select existing one)
  • Run command: python3.8 -m venv pandas1
  • activate the environment by:
cd pandas1
source bin/activate

Once environment is activated you will see change in the terminal:

(pandas1) $ deactivate

The command above deactivates the environment.

3. Install Pandas on Linux

3.1. Install Pandas by Pypi

Next step is to install Pandas. The most popular way of installing Pandas is by running:

pip install pandas

You can find more information for Pandas on: pandas - pypi.org.

3.2. Install Pandas by Pypi

If you like to use alternative installation methods you can check the official docs: Installation.

For example Pandas is part of Anaconda - so if you install Anaconda on your system you will get Pandas:

bash ~/Downloads/Anaconda3-2020.02-Linux-x86_64.sh

follow the instructions or check for more details: Installing Anaconda on Linux

3.3. Verify Pandas installation

Finally you can test Pandas installation by running next commands:

pip freeze | grep pandas

result will be:

pandas==1.3.2

4. Conclusion

To summarize, in this article, we've seen examples of installing Python and Pandas from a PPA and manually. We've briefly explained these installation methods.

And finally, we've seen how to manage multiple Python/Pandas installations on Ubuntu systems with different package versions.