r/Python • u/pkkm • Sep 24 '23
Discussion Pipenv, pip-tools, PDM, or Poetry?
People who have used more than one of the modern package management tools, which one do you recommend and why?
119
Upvotes
96
u/samettinho Sep 24 '23
I always use poetry which is amazing when you are collaborating. It has a little overhead for the first time but it totally worths the effort.
One of the main benefits is that when I install a package and commit the dependency update, the next person using the repo can have the same exact package.
If you are working alone and not collaborating, and doing experimental stuff, you may simply use conda/pip, etc.
11
u/Dogeek Expert - 3.9.1 Sep 25 '23
I've tried a bunch of them :
pip3, it works, need to not forget to switch into the virtual env though, so it's a bit of a pain. Also, locking package versions is a chore.pip-tools, it's what we use at work. Honestly it's pretty simple, but you still need to activate the venv manually, you don't have any tooling for extra scripts, it requires a lithany of requirement files, and additionnal, non trivial and explicit compilation step, no support forpyproject.tomleither or PEP621pdmit shows a lot of promise honestly, and I should try to use it more. PEP621 compliant, build backend agnostic, you define everything in one place, it handles the venv for you (or rather__pypackages__but that PEP has been abandonned unfortunately). Last time I used it it also lack support for private pypi repos and multiple dependency groups.poetrymy default choice nowadays. My biggest gripe with it is that the dev team seem to not care at all about backwards compatibility. They used to regularly introduce breaking changes even in minor version bumps (from 1.0 to 1.1 for instance or 1.1 to 1.2) making it a bit of a nightmare, especially with CI. Configuring it is also not that trivial, between the config.toml file thatpoetry configwrites to, the env vars that sometime don't work in docker, writing a good dockerfile when using poetry is sometimes hellish if you want to avoid 1.4GB images (when starting from python-slim, or alpine, it's awful)Pipenvonce, and it was... not for me. I don't like the syntax it forces,Pipfileis used just forPipenv, it doesn't do anything more thanpip-toolsin my opinion, except abstracting away the locking part of the flow.I saw
hatchmentionned a bunch of times in this thread, but have yet to try it. For now, my choice is onpoetryfor personal and professional projects when I can. Using it in CI/CD, along with containerization can be a bit of a nightmare at times, especially when you want small images, but of all the tools I've tried, it's the most mature, has all the features I need. It's also non-standard unfortunately regarding PEP621, which is a bit of a shame, but hopefully it'll get support.In the future though, I do think
pdmwill be my go-to though. It's a shorter command too, and if it works as well asnpmdoes for nodejs, and gets faster dependency resolution, it's gonna be a no brainer.5
u/jami5701 Sep 25 '23
pip venv "python -m" and this guy made a point
33
u/JamzTyson Sep 24 '23
Poetry, because it simplifies the package management process, provides robust dependency resolution, and offers a user-friendly and modern approach to managing Python projects, packages, and publishing. It is well supported, well documented, and integrates well with other tools including virtualenv, conda, and (important for me) with PyCharm.
12
u/monorepo PSF Staff | Litestar Maintainer Sep 24 '23
We've swapped from Poetry to PDM with the hatchling build backend recently after fighting bugs and speed issues in Poetry. It is mostly the same command-wise, but dependency resolution times no longer take > 2+ minutes
Another option is Hatch, but if I could mix featuresets I would choose all of PDM + Hatch's environment matrix
22
u/robml Sep 24 '23
PDM, people don't use it but it is by far one of my favorites and is actively maintained. Sometimes if I have had an issue (which isn't often) it's been resolved in less than 24-48 hours.
4
u/GlobalRevolution Sep 25 '23
pyenv + venv solves every problem I've had.
I've tried a lot of these package manager solutions over the years (decade?) and they all end up bloating and breaking and I need to switch everything to the new fad of the month like Javascript frameworks.
Lately I've had the most success keeping it as simple as possible and it has been great. I use pyenv, which doesn't have a python dependency, to manage multiple python versions in my environment. From there I just use built in venv for my projects. It's dead simple and easy to know what's going on and I can confidently try new projects without worrying about destroying my environment or finding a new bug in my package manager.
27
u/EmptyChocolate4545 Sep 24 '23 edited Sep 24 '23
pip, IE vanilla setuptools
Conda if you need to control things outside python/in the env.
7
u/nightslikethese29 Sep 24 '23
We use pipenv at work
12
u/Interesting_Fly_3396 Sep 24 '23
Just use pip with venv. Maybe with pip-tools. And use conda only if you really need to. Like managing cuda stuff for deep learning or so.
Poetry and pipenv are in my experience overcomplicating everything. PDM is the new cool kid, not sure about it.
6
u/wineblood Sep 24 '23
We've switched to PDM at work. It promises a lot of great things but like all tools, the documentation is trash.
3
u/[deleted] Sep 25 '23
I like Poetry, but there's a little bit of "simple now, complex later" when you want to use Poetry with CI or even tox. PyCharm and VSCode both support Poetry, but that's slightly more complex than a local venv as well. Been using pip-tools recently because it's more straightforward to search my venv with an IDE.
Here's how to do a simple project with pip-tools. A short, modest "pros and cons" at that link.
https://www.foundationsafety.com/setuptools
3
u/SL1210M5G Sep 26 '23
Pipenv is a failed project. Someone already wrote up a good explanation of why it’s not a good option. I personally have a vendetta against it because for some reason my company decided to use it as the standard Python tool in our deployment pipelines.
Poetry is the future in my opinion, I’m seeing more and more people using it and it’s the closest thing to Node’s NPM/Yarn.
If it were up to me Mamba (Conda) + Poetry is the perfect combo.
13
u/[deleted] Sep 24 '23
poetry hands down
6
u/aldanor Numpy, Pandas, Rust Sep 24 '23
mamba
14
u/DigThatData Sep 24 '23
just use venv. keep it simple.
8
u/0rionsEdge Sep 24 '23
For pure Python packages: poetry. It's the easiest and most reliable tool of the options I have tried. Avoid pipenv. It used to be good several years ago, but it's horribly broken these days.
I haven't tried PDM yet, so I have no strong opinions.
As for pip-tools, I personally found it far too complicated to be worth the time to set up.
For mixed language packages, your options are more limited. For c/c++ mix-ins, venv+ setuptools is your only real choice. ( in theory poetry can do it too, but it's an undocumented capability) For Rust, I can recommend maturin.
12
u/CynicalAndGoofy Sep 24 '23
PDM. Faster than Poetry and integrates better with Tox.
2
u/illusionofsanity Sep 25 '23
For the libraries that I maintain at work, I recently switched over to Hatch[1]. It works pretty well. The only frustration is that you can't configure private repos like you can with poetry.
For our applications we used pip-tools while more recently we're exploring poetry. I quite like poetry for applications.
[1] https://hatch.pypa.io/latest/
5
u/39dotyt Sep 24 '23
poetryI tried
pipenvbecause it's coming from pypa, but had a few bugs with it not being able to correctly install os-specific version of the package after thepipenvupdate (a regression). And I found it's bad when there are people working on different OS-es because it generates (at least, used to when I last looked at it) OS-specific lock-file. E.g., if you setup your pipenv project on Linux, it won't guarantee that it will work on macOS. And running pipenv on macOS will change your lockfile, which neglects the purpose of having a lockfile.poetrydoesn't have these issues. It's not ideal, and I spent noticeable amount of time configuring OS-specific deps in pyproject.toml, but it works properly after you set it up. Plus, it can build wheels and publish your packages to pypi.Using bare
pipis bad because it doesn't have a notion of having separate "deps" and "deps.lock", which is super useful for maintaining clean "deps" and ensuring a reproducible environment via the lockfile (this saves you from a ton of bugs). You can invent it yourself, by having your deps inrequirements.txtand doing apip freezetorequirements.txt.lock, but this adds extra work to your plate and won't solve OS-specific deps nicely.condais cool when you are running someone else's project that usespipor want to do a quick experiment without setting up apoetryproject.3
u/Kaiser_Wolfgang Sep 24 '23
Venv because of simplicity, I was using Pipenv for over a year but switched to venv because Pipenv gets weird when it comes to server permissions when I deployed my python app so I decided just to switch to venv and have had no issues
3
u/Existing-Account8665 Sep 25 '23 edited Sep 25 '23
I'm surprised Poetry is still so popular, after the devs literally added a random 5% chance of crashing your build, this time last year.
Hope y'all enjoy Poetry's unique features and development process.
https://github.com/python-poetry/poetry/pull/6297/commits/e02675716d920e1227ce1013a718b33b202d88f4
(first line indented more by me, for your reading pleasure on Reddit. Otherwise that's literally the code from Poetry's commit history)
3
u/hidazfx Pythonista Sep 24 '23
I've always used pip and venv, and I've been a Python developer professionally going on 3 years.
3
u/ac130kz Sep 24 '23
Poetryis a "safe" option, but it's not PEP 621 compatible yet (they are working on it), the installs are slow.PDMfixes these, has its own quirks: it's a bit rough around the edges, a bug here and there, totally a viable option still. I really want to see whereryemight take off, for now though, it's alpha stage software.3
u/KrazyKirby99999 Sep 24 '23
Poetry, very simple to install and use. PDM is extremely similar, but only Poetry has PyCharm support out of these two.
3
u/[deleted] Sep 24 '23
Pip supremacy
2
u/anentropic Sep 24 '23
There is also Hatch (I haven't used it though)... I can see in this reply https://www.reddit.com/r/Python/comments/udpzri/hatch_100_modern_extensible_python_project/i6jajz3/?utm_source=share&utm_medium=mweb3x&utm_name=mweb3xcss&utm_term=1&utm_content=share_button a year ago the author says it's a bit more agnostic about applications vs libraries, where Poetry was more about applications. (I'm not sure I agree but it gives some opinion on one vs the other)
I think pipenv is a bit out of favour, I didn't look back after switching from that to Poetry a few years ago.
pip-tools is a bit more manual and clunky, but it's useful in application deployment scenario where you want to generate pinned requirements.txt then maybe install from that in Docker file with only vanilla pip. It's a bit more basic and explicit but useful.
PDM looks worth a try on my next project!
2
u/MikeDev1 Sep 24 '23
Hatch.
I use Python for deep learning projects and install the right version of Pytorch for Pipenv, PDM and Poetry is a nightmare. Plus, the environment system in hatch fits very well with my needs
2
u/mrswats Sep 24 '23
I think poetry adds a lot of overhead. I've been lately using pip-tools and works wonderfully. Keep it simple with not too much extra dependencies.
2
u/neomage2021 Sep 24 '23
Poetry 100%
1
u/chub79 Sep 24 '23
I stuck with pip+venv for years and was quite happy with it. Then, for work reason I tried PDM and since then I've switched all my projects to it.
1
u/a_menezes Sep 24 '23
pip + virtualenv + asdf
1
u/Legendary-69420 It works on my machine Sep 25 '23
I use poetry inside venv by setting create virual env to false. I find it more comfortable over using poetry normally.
1
u/tankerdudeucsc Sep 25 '23
I only have one comment about this. And that is that packaging in Python has the weakest story of all languages. Love Python but come on community.
Let’s start aligning and pick one and maintain it. So many options and too many competing interests.
1
u/zanfar Sep 25 '23
Poetry.
I tried a few package management tools, but stopped when I found one that worked. So I can't say that there aren't better tools, or that the tools I abandoned haven't improved. However, I don't feel any need to fix something that isn't broken.
1
u/saint_geser Sep 25 '23
These days Poetry
1
u/[deleted] Sep 26 '23
New to these things can someone shed some light what they are?? And I have used pip for lib or module installation and speaking of poetry, I'm a fresher test automation engineer in work I have used poetry to run my test scripts but still none of em told what it is and why we do ....
1
u/shockjaw Sep 26 '23
I’d recommend mamba or conda, in that order.
1
u/zzo0M Nov 19 '23
I have been using poetry exclusively for the last couple of years. In my opinion there is nothing better for dependency management right now.
1
u/AggravatingMix2433 Jan 31 '24
https://www.youtube.com/watch?v=Gr9o8MW_pb0
1
u/[deleted] Sep 24 '23
Anything but poetry. I've had so many issues...
1
u/357951 Sep 24 '23
prod specific requirements to go requirements/prod.txt
dev specific requirements to go requirements/dev.txt
they don't overalap.
and a simple script to create a pin. no hassle, no overhead, no dependencies, no over-engineering.
1
u/Joeboy Sep 24 '23 edited Aug 17 '26
Badge soup bells pause copper escape
This post was anonymized with Redact
1
u/suprjaybrd Sep 24 '23
poetry, it works well
1
u/Yokhen Sep 24 '23
Poetry ALL THE WAY.
1
u/Almostasleeprightnow Sep 24 '23
I recently switched from mainly using miniconda to mainly using poetry. The reason: I wanted a tool that used pip first, that used default virtual venvs, that helped me understand pyproject.toml.
Now that I understand pyproject.toml a little better, I may look into something else, but poetry is working great for me right now
1
u/thedeepself Sep 24 '23
I'd never heard of hatch before today. Here's a link - https://hatch.pypa.io/latest/
and here is PDM - https://pdm.fming.dev/
1
u/[deleted] Sep 24 '23 edited Sep 24 '23
Use poetry. You can still install it with pip, which should generally still be at least one pathway to install things. Pip compatibility is nice because it makes it usable everywhere.
pdm looks like it might work, but I think it's competing with poetry vs exceeding poetry.
Don't use: pipenv, pip-tools or conda. pipenv and Pipefile probably never should have been promoted by pypa. pip-tools is really strange - compiling python and building things. Conda has a bunch of edges to it that make it somewhat exotic/non-standard. And when you hit those edges, they break things.
1
u/[deleted] Sep 25 '23
None, I use nix-shell.
-1
u/thedeepself Sep 24 '23
One aggravating thing about pipenv and poetry is that you cannot use the up-arrow in windows to navigate and re-use a command.
0
u/Wowawiewa Sep 24 '23
Poetry. Less congestion in the list of dependencies to install, easy to split dependencies into groups and it’s easier to maintain package updates..etc
0
u/[deleted] Sep 24 '23
Pipx , but venv is better and simple
-1
u/emoutikon Sep 24 '23
Pipenv4lyf
-5
u/Slayer91Mx Sep 24 '23
I think Poetry is for very big projects, but I have never used it.
21
u/[deleted] Sep 24 '23
[removed] — view removed comment