Python Package Managers: Pip and Conda – A Complete Beginner’s Guide

When you start programming in Python, one of the first challenges you might face is how to manage the libraries (or “packages”) you will need in your projects. This is where package managers come into play, aiming to facilitate the installation, updating, and removal of libraries, keeping your development environment well-organized.

Below, I present an overview of the two most widely used package managers in Python: pip and conda. I’ll also offer some guidelines on how to use them, especially for those who are just beginning their journey with the language.

Why Use Package Managers?

Imagine you need a specific library for creating charts or performing data analysis.

Instead of manually downloading files and dealing with complicated settings, you simply type a few commands in the terminal.

The package manager takes care of everything behind the scenes: downloading the right library, checking dependencies, and placing everything in the correct location.

Using package managers has several benefits, such as:

  • Making it easy to install, remove, and update libraries.
  • Keeping your development environment organized.
  • Providing quick access to thousands of community-maintained packages.

Main Managers: pip and conda

pip

  • The default package manager in most Python installations.
  • Works directly with the Python Package Index (PyPI), an online repository hosting a majority of Python libraries.
  • Typically installed by default when you install Python on your system.

conda

  • Functions as both a package manager and an environment manager, supporting not only Python but also other languages like R, Ruby, Lua, Scala, Java, JavaScript, C/C++, FORTRAN, etc.
  • Part of the Anaconda Project; can also be installed in a slimmer way via Miniconda.
  • Natively supports virtual environments, allowing more controlled management of dependencies, even for non-Python packages.

It’s possible to have pip and conda together on the same system, but it’s advisable to use virtual environments to avoid conflicts, as each manager has its own way of organizing packages.

Installing pip

In most cases, when you install Python (version 3.4 or later), pip is included by default. However, if you need to check or manually install pip, follow the steps below.

Windows

Check if Python is installed:

Open the Command Prompt (CMD) and type:

python --version

If you don’t see a valid Python version, download and install Python from the official website.

Check if pip is installed:

In the same Command Prompt, type:

pip --version

If this shows a pip version, it’s already installed. Otherwise, proceed to the next step.

Install or upgrade pip:

Type the following command:

python -m ensurepip --upgrade

This will ensure pip is installed or upgraded on Windows.

Linux/Mac

Check if Python is installed:

Open the Terminal and type:

python3 --version

If a valid Python version is not shown, install Python using your system’s package manager (e.g., apt-get on Ubuntu/Debian, dnf on Fedora) or download from the official Python website.

Check if pip is installed:

In the Terminal, type:

pip3 --version

If you don’t see a valid version, install pip via your distribution’s package manager. For example, on Ubuntu/Debian:

sudo apt-get update
sudo apt-get install python3-pip

After that, we can test with the command below.

pip3 --version

On macOS, pip is usually included with Python. Otherwise, you can install it with Homebrew:

brew install python

Installing conda

To install conda, you can choose either Anaconda, which comes bundled with many data science libraries, or Miniconda, which is a more lightweight option.

Windows

Download the installer from the Anaconda or Miniconda page.

Run the installer and follow the on-screen instructions.

Confirm that conda is installed:

Open the Command Prompt (or the Anaconda Prompt) and type:

conda --version

If a conda version is displayed, the installation was successful.

Linux/Mac

Download the installation script from the Anaconda or Miniconda website (choose the Linux or macOS version).

Open the Terminal and navigate to the folder where the script was downloaded.

Make the script executable and run it:

chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh

(The file name may differ depending on the version and operating system.)Follow the installation instructions on-screen.Verify the installation:

Follow the installation instructions on-screen.

Verify the installation:

conda --version
or
./_conda --version

Once you have pip or conda installed, you can follow the instructions in the previous posts to manage packages in your Python environment effectively. Enjoy exploring Python’s ecosystem with these powerful tools!

Installing Libraries with pip and conda

The installation commands for pip and conda are quite similar. For example, to install the popular Pandas library, you can use:

# Option 1 (pip)
pip install pandas

# Option 2 (pip on Linux/Mac with Python 3)
pip3 install pandas

# Option 3 (conda, using the "anaconda" channel)
conda install -c anaconda pandas

Note: The -c anaconda parameter in conda install specifies which channel (repository) to use. There are multiple channels available, each offering different versions and packages. It’s a good idea to check conda’s official documentation for more options.

“If the error shown in the figure above appears, create the virtual environment using the commands below.”

Virtual Environments

To avoid conflicts between different projects, it’s highly recommended to use virtual environments—whether through conda or Python’s built-in venv tool.

Initially, install venv with the command below.

sudo apt install python3.12-venv

For example, to create and activate an environment with venv:

# Create a virtual environment called "myenv"
python -m venv myenv

# Activate the environment (Windows)
myenv\Scripts\activate

# Activate the environment (Linux/Mac)
source myenv/bin/activate

After that, we can repeat the installation command.

pip3 install pandas

Using conda:

# Create an environment named "myenv" with Python 3.10
conda create -n myenv python=3.10

# Activate the environment
conda activate myenv

Removing Libraries

If you decide you no longer need a package, you can remove it with a single command:

# Remove with pip
pip uninstall pandas
pip3 uninstall pandas

# Remove with conda
conda remove pandas

Listing Installed Packages

It’s important to know which packages are installed in your development environment, especially if you plan to share your project or migrate to a different machine. To list installed packages:

# List all packages installed with pip
pip list
pip3 list

# List all packages installed with conda
conda list

Updating Packages

The process for updating packages differs a bit between pip and conda:

  • pip updates one package at a time.
  • conda can update a single package or all packages in an environment simultaneously, without breaking dependencies.

Below are some examples, again using Pandas:

# Update Pandas with pip
pip install --upgrade pandas
pip3 install --upgrade pandas

# Update Pandas with conda
conda update pandas

# Update all packages in the conda environment
conda update --all

Other Ways to Install Python Packages

On many Linux distributions, the main Python libraries (such as Pandas, NumPy, TensorFlow, etc.) can be found in the official repositories. In that case, you can install them using your distribution’s package manager:

# Ubuntu/Debian
sudo apt-get update
sudo apt-get install python3-pandas

# Fedora
sudo dnf install python3-pandas

One advantage of using your Linux system’s package manager is that these packages are generally vetted by the distribution’s community, providing an additional layer of stability and official support.

However, you might not always get the latest versions, and the range of available packages can be more limited than what pip or conda offers.

Creating and Distributing Your Own Packages

Both pip and conda let you make your own libraries available so others can install them easily.

It’s a bit more advanced, but it’s helpful to know that there are tools to package your code and upload it to PyPI or to a custom conda channel.

Conclusion

Package managers like pip and conda are essential tools for anyone developing in Python. Knowing how to install, remove, and update packages helps keep your environment organized and productive, and prevents compatibility issues.

To learn more, check out the official pip documentation and the official conda documentation. You’ll find more advanced tutorials, troubleshooting help, and best-practice guides.

Extra Tip: If you’re a beginner, don’t worry about all these options. Practice will make it clearer over time. You’ll soon figure out whether you only need pip, conda, or both!

Happy installing, and enjoy coding with Python!

See more:

Socket UDP Python Chat

Socket TCP Python make a chat

Best IDE for Python?

Python get metadata from images and pdfs

Install Python on Windows 11

Python: show my TCP and UDP ports

Juliana Mascarenhas

Data Scientist and Master in Computer Modeling by LNCC.
Computer Engineer