{"id":306,"date":"2021-09-13T00:00:00","date_gmt":"2021-09-13T00:00:00","guid":{"rendered":"https:\/\/tac.debuzzify.com\/?p=306"},"modified":"2023-06-27T05:10:27","modified_gmt":"2023-06-27T05:10:27","slug":"virtualenv-alternative-for-python-dependency-management","status":"publish","type":"post","link":"https:\/\/www.the-analytics.club\/virtualenv-alternative-for-python-dependency-management\/","title":{"rendered":"Don’t Use Virtualenv to Manage Python Dependencies. Upgrade to Poetry."},"content":{"rendered":"\n\n\n

I was daunted by the complexities of projects when I started my data science career. We were using Virutalenv in all our Python projects.<\/p>\n\n\n\n

I’m impressed by the Node Package Manager (npm) and always wondered why we don’t have one like that in Python.<\/p>\n\n\n\n

\n

I was yearning for a single tool to maintain isolated environments, manage dev and production dependencies, packaging, and publishing.Thankfully, we have Poetry now.<\/p>\n<\/blockquote>\n\n\n\n

In a nutshell, Poetry is a tool for dependency management and packaging in Python.<\/p>\n\n\n\n

But this official definition is incomplete because I found Poetry does more than manage dependencies and packaging.<\/p>\n\n\n\n

Poetry is not a substitute for virtual environments. It complements them with intelligent ways to manage environments and more.<\/p>\n\n\n\n

Here’s why I fell in love with Poetry at first sight.<\/p>\n\n\n\n

\n
\n
\n

Grab your aromatic coffee <\/a>(or tea<\/a>) and get ready…!<\/p>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n

Unlike Virtualenv, I can rename and relocate my project with Poetry.<\/h2>\n\n\n\n

Virtual environments are tied to a specific path. If I move or rename the project folder, the original path doesn’t change.<\/p>\n\n\n\n

I’d be in great trouble if I ever wanted to do it.<\/p>\n\n\n\n

Whenever I changed the path, I created a new virtual environment and installed packages.<\/p>\n\n\n\n

It was painstaking.<\/p>\n\n\n\n

Virtualenv has a --relocatable<\/code> flag to help with it. But I’m not satisfied with this option either. Whenever I installed a new package, I had to flag the environment. --relocatable<\/code>.<\/p>\n\n\n\n

It’s annoyingly repetitive! I believe data scientists<\/a> and developers have more significant problems than remembering to run this every time.<\/p>\n\n\n\n

Poetry projects are relocatable.<\/b><\/h3>\n\n\n\n

Poetry isolates the virtualenv from the project. It automatically creates an env at the .cache<\/code> folder in the $HOME directory. When I relocate the project, I can tell Poetry to use the same env in a single command.<\/p>\n\n\n\n