Python Package Managers Explained (2024)

Python

Posted by Crista Perltonon .
Python Package Managers Explained (1)

Python has become one of the most popular programming languages, thanks to its ease of use and extreme versatility. It has an extensive standard library that comes with “batteries included” making it a powerful tool for all kinds of Python users. From data scientists to network engineers, there’s a Python library for everyone.

What makes Python a true power tool is the ecosystem of free and open-source libraries like Tensorflow, Netmiko, and Flask. These can be installed with a single command using a package manager.

In this article, I’ll explain where all these great packages can be found, how Python’s standard package manager works, and some challenges and solutions to be aware of when using Python.

PyPI: The Package Index

Similar to NuGet.org & Npmjs.org, Python also has its own official third-party software repository. The Python Package Index (PyPI) is a repository of software that hosts an extensive collection of Python packages, development frameworks, tools, and libraries.

PyPI packages allow developers to share and reuse code rather than having to reinvent the wheel. As PyPI grew, the need for a package manager became so apparent that Python eventually created its own standard package manager: pip.

Pip: The Standard Package Manager

Pip is built-in into Python and can install packages from many different sources. But PyPI.org is the primary and default package source used.

By default, pip installs packages onto a project’s global Python environment resulting in packages being accessible by all projects. This can be an issue due to packages being dependent on specific versions of other packages. Since all packages are in a global environment, it’s easy to run into a dependency conflict that may prevent your application from building.

Thankfully, pip automates package management by first resolving all dependencies and then proceeding to install the request packages. However, the standard method for preventing dependency conflicts is to create separate Python environments for each project.

Virtual Environments & Virtualenv

In the Python world, a virtual environment is a folder containing packages and other dependencies that a Python project needs. The purpose of these environments is to keep projects separate and prevent dependency, version, and permission conflicts.

Imagine a script that relies on 1.10 of the package NumPy, but a different script requires version 1.20. This is a slight problem because there’s a breaking change in 1.19. If you install everything into a global python environment (e.g. the default pip setting) then one of these scripts might not work.

Virtualenv is a tool that allows the creation of named virtual environments where you can install packages in an isolated manner. Each environment has its own installation directories and doesn’t share libraries with other virtual environments (including globally installed libraries).

For example, one environment for web development and a different environment for data science can be created with their own set of libraries.

Python Package Managers Explained (2)

Pip Alternatives (Pipenv & Poetry)

Pip is the “original” Python package manager that others have attempted to improve upon. Pipenv & Poetry are two package managers that have done this with great success.

Pipenv is a package management tool that “aims to bring the best of all packaging worlds” to Python. Pipenv is similar in spirit to Node.js’s npm and Ruby’s bundler. It’s popular among the Python community because it merges virtual environments and package management into a single tool. While pip is sufficient for personal use, Pipenv is recommended for collaborative projects as it’s a higher-level tool that simplifies dependency management for common use cases and can create virtual environments.

Poetry prides itself on making Python packaging and dependency management “easy”. Besides package management, it can help build distributions for applications and deploy them to PyPI. It also allows the declaration of the libraries a project depends on and installs/updates them avoiding any conflicting package requirements. Furthermore, Poetry isolates development versus production dependencies into separate virtual environments.

Conda: Alternative Package Management

Conda is a multi-purpose package management tool. It manages package dependencies, can create virtual environments for applications, installs compatible Python distributions, and packages applications for deployment to production. It originated from Anaconda, which started as a data science package for Python. Conda installs packages from Anaconda rather than PyPI and can be used with multiple programming languages.

Compared to Pip, the package selection is much smaller, but what Conda lacks in quantity it makes up for in quality. Anyone can publish to PyPI, but only packages curated by Anaconda are published in its repository. While Anaconda requires a paid subscription, it grants access to thousands of curated packages and provides support as well. Conda is an ideal package manager for those that are willing to pay to not worry about the license, quality, and vulnerability issues when dealing with third-party/open-source packages.

Getting Started with Python Package Managers

Pip is the ideal starting place. It comes with Python, is easy to understand, and has an abundance of related resources. However, if you’re working on anything more than a personal project you will likely need to create virtual environments. For that, Pipenv and Poetry are more convenient options than using pip and Virtualenv together.

Alternatively, Conda can be used as a Swiss army knife package management tool. It has everything you need in one tool and access to packages curated by Anaconda. However, it requires a paid subscription, its repository (Anaconda) has significantly fewer packages, and it has fewer related resources available than PyPI and its package managers.

Managing Python packages is only the tip of the iceberg when it comes to using Python in development environments. Read our guide to learn how to master Effective Package Management in Python!

Python Package Managers Explained (3)

Crista Perlton

View Comments (0) ...

Python Package Managers Explained (2024)

FAQs

Python Package Managers Explained? ›

Setting up development environments: Package managers help developers create consistent development environments across different machines by specifying the package version numbers. In pip this is in the form of a requirements. txt file, in conda this is an environment. yml file and in poetry this is a pyproject.

How does the Python package manager work? ›

The pip command looks for the package in PyPI, resolves its dependencies, and installs everything in your current Python environment to ensure that requests will work. The pip install <package> command always looks for the latest version of the package and installs it.

How does PDM work Python? ›

PDM can manage virtual environments (venvs) in both project and centralized locations, similar to Pipenv. It reads project metadata from a standardized pyproject. toml file and supports lockfiles. Users can add additional functionality through plugins, which can be shared by uploading them as distributions.

What is a package manager for dummies? ›

Package managers typically maintain a database of software dependencies and version information to prevent software mismatches and missing prerequisites. They work closely with software repositories, binary repository managers, and app stores.

Is poetry better than pip? ›

To manage these dependencies in your code, Poetry is a great tool for those working with more complex and diverse projects with a higher number of dependencies. While Pip and Conda are still viable options, they are more suited for smaller environments that are less complex.

Which Python package manager should I use? ›

The most widely used Python package manager is pip (short for “pip installs packages”). It comes pre-installed with Python versions 3.4 and later. Pip allows developers to easily install packages from the Python Package Index (PyPI) and other repositories.

Why use Python package manager? ›

Python Package Manager (PyPM) is a Python utility intended to simplify the tasks of locating, installing, upgrading and removing Python packages. It can determine if the most recent version of a software package is installed on a system, and can install or upgrade that package from a local or remote host.

What is the difference between PDM and PLM? ›

PDM systems are focused on the engineering and design stage, so might only integrate with your CAD system. PLM systems cover stages of the product life where files are created around the concept, managing invoicing, managing parts, and maintenance reports. These stages need to manage file types other than CAD files.

What does a PDM install do? ›

pdm install will check the lock file and relock if it mismatches with project file, then install. pdm sync installs dependencies in the lock file and will error out if it doesn't exist. Besides, pdm sync can also remove unneeded packages if --clean option is given.

Where does PDM install packages? ›

The installer will install PDM into the user site and the location depends on the system:
  • $HOME/. local/bin for Linux.
  • $HOME/Library/Python/<version>/bin for MacOS.
  • %APPDATA%\Python\Scripts on Windows.

Why should I use a package manager? ›

The package manager will provide a method to install new dependencies (also referred to as "packages"), manage where packages are stored on your file system, and offer capabilities for you to publish your own packages.

What are the three biggest advantages of using a package manager? ›

  • Package managers are essential tools for any software development project. ...
  • • Easier to install and manage libraries and dependencies.
  • • Helps maintain consistent versions of libraries and dependencies across multiple environments.
  • • Automates tedious tasks like updating packages.
Jan 6, 2023

What is a package manager example? ›

Examples of Package Managers: npm and Yarn for Javascript. Bundler for Ruby. Apache and Gradle for Java.

Why not use conda? ›

Slow performance: Because Anaconda comes with so many pre-installed packages, it can slow down the performance of your computer, particularly when running resource-intensive tasks. Compatibility issues: Some of the packages included in Anaconda may not be compatible with certain versions of Python or other packages.

What is the difference between Conda and pip? ›

Conda installs binary packages, which means the packages include compiled code. This can make the installation process faster and more reliable, especially for packages with complex dependencies. Pip, by contrast, often installs packages from source, which means the code is compiled during the installation process.

Why use poetry for Python? ›

Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Poetry offers a lockfile to ensure repeatable installs, and can build your project for distribution.

How does a package manager work? ›

The package manager will provide a method to install new dependencies (also referred to as "packages"), manage where packages are stored on your file system, and offer capabilities for you to publish your own packages.

How does conda package manager work? ›

Conda checks everything that has been installed, any version limitations that the user specifies (for example, the user wants a specific package to be at least version 2.1.3) and determines a set of versions for all requested packages and their dependencies that makes the total set compatible with one another.

How does Python import module work? ›

You need to use the import keyword along with the desired module name. When interpreter comes across an import statement, it imports the module to your current program. You can use the functions inside a module by using a dot(.) operator along with the module name.

How does Python know where to find packages? ›

Python imports work by searching the directories listed in sys. path . So Python will find any packages that have been installed to those locations.

Top Articles
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 5487

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.