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.
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.
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:
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.
(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:
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.
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!
We use cookies on our website remembering your preferences and visits. By clicking “Accept All”, you consent to the use of ALL the cookies. Visit " Settings" to provide a controlled consent./ Usamos cookies no site lembrando suas preferências e visitas. Clicando em “Aceitar todos”, você concorda com o uso de TODOS os cookies. visite "Configurações cookies" para um consentimento controlado.
This website, uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience. **/** Este site usa cookies para melhorar a sua experiência enquanto navega pelo site. Destes, os cookies que são categorizados como necessários são armazenados no seu navegador, pois são essenciais para o funcionamento das funcionalidades básicas do site. Também usamos cookies de terceiros que nos ajudam a analisar e entender como você usa este site. Esses cookies serão armazenados em seu navegador apenas com o seu consentimento. Você também tem a opção de cancelar esses cookies. Porém, a desativação de alguns desses cookies pode afetar sua experiência de navegação.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-advertisement
1 year
Set by the GDPR Cookie Consent plugin, this cookie is used to record the user consent for the cookies in the "Advertisement" category
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
O cookie é definido pelo consentimento do cookie GDPR para registrar o consentimento do usuário para os cookies na categoria "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". Este cookie é definido pelo plug-in GDPR Cookie Consent. Os cookies são usados para armazenar o consentimento do usuário para os cookies na categoria "Necessary",
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other".
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
O cookie é definido pelo plug-in GDPR Cookie Consent e é usado para armazenar se o usuário consentiu ou não com o uso de cookies. Ele não armazena nenhum dado pessoal.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Cookie
Duration
Description
pll_language
1 year
The pll _language cookie is used by Polylang to remember the language selected by the user when returning to the website, and also to get the language information when not available in another way.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Cookie
Duration
Description
_tccl_visit
30 minutes
This cookie is set by the web hosting provider GoDaddy. This is a persistent cookie used for monitoring the website usage performance.
_tccl_visitor
1 year
This cookie is set by the web hosting provider GoDaddy. This is a persistent cookie used for monitoring the website usage performance.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Cookie
Duration
Description
__gads
1 year 24 days
The __gads cookie, set by Google, is stored under DoubleClick domain and tracks the number of times users see an advert, measures the success of the campaign and calculates its revenue. This cookie can only be read from the domain they are set on and will not track any data while browsing through other sites.
_ga
2 years
The _ga cookie, installed by Google Analytics, calculates visitor, session and campaign data and also keeps track of site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognize unique visitors.
_gat_gtag_UA_199766752_1
1 minute
Set by Google to distinguish users.
_gid
1 day
Installed by Google Analytics, _gid cookie stores information on how visitors use a website, while also creating an analytics report of the website's performance. Some of the data that are collected include the number of visitors, their source, and the pages they visit anonymously.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Cookie
Duration
Description
test_cookie
15 minutes
The test_cookie is set by doubleclick.net and is used to determine if the user's browser supports cookies.