Poetry vs Conda

Introduction

Poetry vs Conda
Poetry vs Conda

We will go over the differences between Poetry vs Conda.

Did you know that Conda works with different programming languages?

I’ve always used Conda in my Python projects but the last few months I was introduced to Poetry and I’ve been liking it a lot. I think it has it’s place so I wanted to write about it and see how it compares with Conda and whether or not it’s a good fit for your project.

We will break down this in the following sections:

  • Quick summary differences between Poetry and Conda
  • Detailed Comparison Conda vs Poetry

I have used both Conda and Poetry successfully in various projects and they both work like a charm. I believe both have a place in my heart but which one do I use the most and why? I will be breaking down this and you can make your own mind up.

We will go point by point on how both compare in various tasks and what is the advantage of each of them.

Quick Comparisson

If you don’t want to spend a lot of time going through the differences between the two, I made a quick comparison table for you to go through and see the differences between the two and hopefully make a choice for yourself.

For more detailed information and how these two compare you will need to keep reading on the sections below as I answer very popular questions and I go into depth on their differences so you can make a more educated choice for your next project.

CondaPoetry
InstallationEasyEasy
Ease Of UseEasyEasy
Package SupportVery goodVery good
Dependency ResolutionGoodExcellent
Package SupportGoodAverage
SecurityGoodAverage
SpeedAverageSlow
IntegrationGoodAverage
FeaturesLimitedGood
PopularityVery GoodBad

What is the Difference between Conda and Poetry

Conda is basically a package management system and environment setup application. It lets you control both in an easy and abstracted way. Unlike poetry Anaconda works with different languages as well and provides a generally more versatile and tested tool compared to Poetry which is relatively new in the field and only works with Python.

Conda is bundled in with a lot of installers and works very well with dockerization of your system. On the other hand Poetry is not a stand out prebundled application and does have it’s caveats however it also works well with docker if setup properly.

Closing it’s important to note that Poetry works very well as an environment replication across different platforms whereas with Conda you will need to do extra steps to make it work properly. One of them is destroying your environment and specifying at least the right version of Python where the packages were deployed with.

Is Poetry A Replacement for Conda

As we discussed earlier Poetry can be a replacement for Conda however it does rely on you setting things up properly and going the extra mile in terms of configuration.

If you loosen up a bit your definition of replacement and mean using it at a high level without having to use PIP (aside from the initial install) then sure you can say that poetry can replace Conda for your day to day use. Essentially you can think of it as a wrapper for both virtualenv a Python package that creates environments combined with PIP installer in those environments.

Now that we clarified this I would like to stress out the fact that based on your viewpoint this can go either way so please don’t blame me for which definition I give. I prefer to state the facts and let you decide.

Detailed Comparison Conda vs Poetry

Now that we went over some definitions lets start diving into the deep waters and break down each feature to help you decide which solution is better for you.

Installation / Update

Conda vs Poetry - Installation
Conda vs Poetry – Installation

The first section we will be covering is the installation and update process of the package itself. Both of these frameworks provide very simple ways of doing it but let’s go more into the specifics to fully understand this process.

For Conda you can install it with the following commands:

$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
--2022-10-12 19:58:49--  https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
Resolving repo.anaconda.com (repo.anaconda.com)... 104.16.130.3, 104.16.131.3
Connecting to repo.anaconda.com (repo.anaconda.com)|104.16.130.3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58693864 (56M) [application/x-sh]
Saving to: ‘/Users/alex/miniconda.sh’

/Users/alex/miniconda.sh                    100%[========================================================================================>]  55.97M  10.6MB/s    in 5.2s

2022-10-12 19:58:55 (10.8 MB/s) - ‘/Users/alex/miniconda.sh’ saved [58693864/58693864]

PREFIX=/Users/alex/miniconda
Unpacking payload ...
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/alex/miniconda

  added / updated specs:
    - brotlipy==0.7.0=py39h9ed2024_1003
    - ca-certificates==2022.3.29=hecd8cb5_1
    - certifi==2021.10.8=py39hecd8cb5_2
....
Preparing transaction: done
Executing transaction: |
done
installation finished.
$ conda --version
conda 4.12.0

As you can see above the process is fairly simple you download a file run it and then it takes care of everything. One extra step I had to do there that is not shown is that I had to add the conda installation in my PATH variable in my shell for zsh you need to edit the zshrc file.

For Poetry you need to go a bit outside your comfort zone and run an external curl command to get an installer script that’s written in Python. This is merely a wrapper to get the right pip package and install it on your system.

This can be accomplished using the following command.

$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -

When it comes to upgrading both systems fairly simple ways of doing so. The commands below show you to do this for PIP.

$ pip install --upgrade pip

As you can tell it’s fairly simple one-liner, similarly poetry has also a more intuitive one liner that lets you upgrade it’s command.

$ poetry self update

Since Conda requires a bit more work to get going I’d say the winner here is Poetry.

Winner: Poetry

Ease Of Use

Conda vs Poetry - Ease Of Use
Conda vs Poetry – Ease Of Use

Both frameworks are very easy to use. However as we can see from all the commands Poetry has an edge here since the command line interface is more intuitive. Furthermore some things in Conda like finalizing the versions of packages you have in your virtual environment require a series of commands. More particularly lets take a look and see how you can do this using a requirements text file.

$ conda list -e > requirements.txt

You can redirect the output of your list command when you finish working. You can also edit the requirements file but that’s a bit harder to do.

With poetry you have a nice package dependency file that allows you to work with versions similar to npm/yarn. If we take a sneak peak this looks like this.

[tool.poetry]
name = "unbiased-coder-project"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.9"
python-dotenv = "^0.20.0"

[tool.poetry.dev-dependencies]
pytest = "^5.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

The important line above is the section that shows the tool.poetry.dependencies. You can define all your packages there along with minor/major versions.

Since poetry has a much more advanced and automated way of doing this I would give this section to Poetry.

Winner: Conda

Package Support

Conda vs Poetry - Package Support
Conda vs Poetry – Package Support

One of the most important aspects is package support. This is very intuitive in this case and we should be taking it very seriously. Below you can see how easy it is to add a package in your poetry setup which also automatically keeps things in a sandbox.

In the case below we are simply adding the python-dotenv package which also updates the package file we examined earlier for us without having to edit any files.

$ poetry add python-dotenv
Creating virtualenv unbiased-coder-project-q3DVRnTY-py3.9 in /Users/alex/Library/Caches/pypoetry/virtualenvs
Using version ^0.20.0 for python-dotenv

Updating dependencies
Resolving dependencies... (3.6s)

Writing lock file

Package operations: 9 installs, 0 updates, 0 removals

  • Installing pyparsing (3.0.9)
  • Installing attrs (21.4.0)
  • Installing more-itertools (8.13.0)
  • Installing packaging (21.3)
  • Installing pluggy (0.13.1)
  • Installing py (1.11.0)
  • Installing wcwidth (0.2.5)
  • Installing pytest (5.4.3)
  • Installing python-dotenv (0.20.0)

When it comes to conda since the environment is already done for you all you need to do is run the install command like this:

 

$ conda create -n myenv python
Collecting package metadata (current_repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
...

$ conda activate myenv

$ conda install bs4
Collecting package metadata (current_repodata.json): done
....
Downloading and Extracting Packages
soupsieve-2.3.1      | 34 KB     | ################################################################################################################################## | 100%
beautifulsoup4-4.11. | 192 KB    | ################################################################################################################################## | 100%
bs4-4.11.1           | 5 KB      | ################################################################################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

$ conda deactivate

It’s pretty obvious from the above commands that the winner here is Poetry. The process is a lot simpler and makes everything a breeze whereas with Conda you have to memorize a lot of commands do things manually. The pro here is that the conda syntax is very similar to PIP which is a common package manager.

Winner: Poetry

Dependency Resolution

Conda vs Poetry - Dependency Resolution
Conda vs Poetry – Dependency Resolution

Another important aspect of a Package manager is dependency resolution. This comes down to personal trial and error and it’s hard to prove with hard facts so I’ll just go ahead and tell you my experience after using both package systems over a long period of time.

I can say here that while Poetry can be extremely slow at some times it’s better at resolving package dependencies. Especially if you are using an odd mix of older package distributions it will resolve those for you and pull what’s appropriate.

The issue with conda is that some packages do not exist by default in the namespace. For example I wanted to add the other python-dotenv which is a package that I commonly use for setting up and reading my env file, to my surprise it wasn’t available in the conda repository. In this case unfortunately the only way around it is to install PIP in your conda environment and then use PIP to install it!

In that case you have to update the version to a later one and this is where most problems stem from. Once you do an update in one of your packages in your requirements file then resolving the rest of the dependencies which are set in stone in requirements can be a very big hassle. Poetry does not have this issue in fact it will do all the heavy lifting for you.

So based on your situation if you don’t really care on using older packages or freezing then both package managers are great, otherwise it’s safer to go with Poetry as it gives you more power and flexibility at the end of the day. Despite the inflexibilities of Poetry I think it still comes ahead as it’s based on PIP and the chances of finding the package you want are very high.

Winner: Poetry

Package Building

Conda vs Poetry - Package Building
Conda vs Poetry – Package Building

This is a feature that Conda simply does not have. With Poetry you can basically bundle and upload your package as is from the build directory that you initialized it in. Since there isn’t much comparison here to do with Conda as you need to do everything manually I’d say when it comes to package building and bundling your code Poetry is the winner without competition.

Winner: Poetry

Security

Conda vs Poetry - Security
Conda vs Poetry – Security

Security is a big aspect of your package manager as it maintains the integrity and reputation of your code from attackers. Since Poetry comes with a lot less dependencies and generally speaking most people that use Poetry tend to use the latest packages (as it depends on PIP under the scenes) I think it has a slight edge over Conda on being more secure.

The idea that Conda has more code and does more things, also introduces more attack vectors in the code and adds space for more exploitation. Generally the less code and components the better for your security.

Since Poetry shines in all of the above I can safely say that it offers a more secure and safe environment to work with.

Winner: Poetry

Speed

Conda vs Poetry - Speed
Conda vs Poetry – Speed

When it comes to execution speed Conda is much better than Poetry. While Poetry is great when it has to do with package dependency resolution it’s extremely slow at doing so.

Conda on the other hand is almost always instant and I believe this is because of how the wheel packages are read and processed. If you do some timed runs in complex projects Poetry will be noticeably slower. However in small projects with a few dependencies you will not notice much of a difference at all and both operations will complete in the same amount of time.

Based on the above statement you can go with whatever is closer to you. I personally don’t think speed is an important factor like the earlier sections since it’s most of the times a one time deployment thing and if it takes a bit longer to do I don’t mind waiting.

Offcourse the situation changes in a more dynamic container like environment where everything is built and executed on the fly. Furthermore if you are using Lambdas in AWS or other server less platforms that do on demand build and deploy before they execute the code this may be an important factor for you. As over time this will build up and give you a hit in your initialization time along with the overall process of running the code.

Winner: Conda

Integration

Conda vs Poetry - Integration
Conda vs Poetry – Integration

When it comes to integration we will be talking how easy it is to add a package management system to a deployment code such as a third party system, more particularly I have in mind these:

  • Docker
  • AWS Lambda
  • Shell script
  • Deployment code such as Jenkins, Azure Devops, Gitlab etc

The most important thing is in all of those is how well it’s scriptable the code can be. To do this we need to examine a few examples of how we can do this from a shell script.

Let’s start by looking first at Conda. In the example above we need to simply download and install Conda and then activate a new environment. This may seem simple but it requires a lot of steps in the process to perform inside a container plus pulling a lot of dependencies.

On the other hand with Poetry since it’s dependent on PIP this runs smoother and the chances that your container already has pip are very high by default making everything even easier. Finally Poetry has a very easy way of running scripts as shown below:

$ poetry run python myscript.py

Yes this is right Poetry basically lets you run things inside the sandbox it creates seamlessly. This is a big bonus as all it would require from you is to initialize and install your packages. If you are someone that has limited experience on writing code and using test cases then Poetry is the solution for you. It also simplifies the process for testing.

Lets see how easy it is to run pytest in your code within the sandbox.

$ poetry run pytest

Similar to above you simply just run the command and this takes care of all the testing and abstraction for you effortlessly. I would say here the judge has an easy choice for which solution is better.

Winner: Poetry

Features

Conda vs Poetry - Features
Conda vs Poetry – Features

When it comes to features as we explained earlier Poetry does a bit more when it comes to Python in specific. On the other hand Conda is a broader used framework that can support more languages and frameworks if needed. To that extent I believe if we are talking strictly about Python Poetry comes on top as it has a much richer feature set and gets more done with less work.

Winner: Poetry

Popularity

Conda vs Poetry - Popularity
Conda vs Poetry – Popularity

Let’s close this final comparison on popularity. For this we will be using the help of google trends to see how well adopted each of those ecosystems are. To make it a bit more fair I’m going to limit this to the last 12 months as Poetry is a fairly newer system to Conda. Since Conda has been around since the start of time it will not be a fair comparison to backdate this popularity graph.

Conda vs Poetry - Popularity
Conda vs Poetry – Popularity

As you can see above Conda still wins by a long margin when it comes to popularity. I would dare say that Poetry is still fairly unknown to the world. One thing to note here is that I had to look for the term Python Poetry which may have reduced a bit the chances of what the user is searching for.

To counter this I tried a variation in the category of programming. Since conda may be easily confused with the snake anaconda and that will bias the google trend results.

This does not discount in any way the Poetry project which I believe does a good job at fixing bugs and supporting the platform. In this case Conda is the clear winner and comes on top in the comparison.

Winner: Conda

Conclusion

We were able to successfully go over Poetry vs Conda, hopefully I answered any questions you may have had and helped you get started on your quest of selecting the right Python Package Management and Environment creation framework for your project.

If you found this useful and you think it may have helped you please drop me a cheer below I would appreciate it.

If you have any questions, comments please post them below or send me a note on my twitter. I check periodically and try to answer them in the priority they come in. Also if you have any corrections please do let me know and I’ll update the article with new updates or mistakes I did.

Would you consider moving from Conda to Poetry?

I personally think both have their place in the right project. It really depends on what you want to accomplish and how you want to go about it. Even though I love poetry I will still be using Conda for most of my projects as I find I do not need most of it’s features.

If you would like to visit the official Poetry documentation here.

If you would like to visit the official Conda documentation you can find it here.

If you would like to find more articles related to Python:

Leave a Comment

Your email address will not be published. Required fields are marked *