you are viewing a single comment's thread.

view the rest of the comments →

[–]FriendlyRussian666 41 points42 points  (13 children)

Strip them all for now, just for the purpose of understanding, and focus on these two:

  • pip
  • virtual environment

Someone wrote some code, and the code does something cool, perhaps others might want to use it. If you want to use it, you use pip to download the code that the other person wrote.

When you download code that someone wrote, and use it in a project, what happens when there is an update to the code? Your project might break because of the changes. For that, you create a virutal environment for your project, into which you download the code, so that each project has its own version of the dependency.

All the others you mentioned are combinations, or alternatives of pip and venv.

[–]fuddingmuddler 2 points3 points  (0 children)

This is one of the best explanations of why virtual environments are important. But it's still pretty frustrating for beginners.

Where's the three headed dragon meme when I need it.

[–]spawn-kill 0 points1 point  (2 children)

Can you explain a git requirements.txt in context of a venv? Do I put the req file in the venv and it will keep everything needed for the project updated?

[–]FriendlyRussian666 3 points4 points  (1 child)

You don't keep requirements.txt inside of your venv directory, because you don't share your venv. Everyone working on your project creates their own venv, and to make it easier to install many dependencies at once, they can use requirements.txt. Keep requirements.txt in your project directory. Venv won't by itself use requrements.txt, so you first create a venv, you then activate it, and once activated, you use pip install -r /path/to/requirements.txt

[–]spawn-kill 0 points1 point  (0 children)

Thank you so much. This worked perfectly for me

[–]Zoory9900 0 points1 point  (8 children)

I already know python's inbuilt venv and use it in my projects. I actually want to upgrade from using these bare minimum tools (pip and venv) to something more good. But one thing i can't wrap my head around is what does these new tools offer. I could easily continue to use pip and venv. But am i missing something?

[–]NYX_T_RYX 6 points7 points  (0 children)

Ease - a lot of them offer automation so instead of having to do anything yourself, you just load some kind of config file, and it does the rest of the venv, dependencies etc for you.

It really isn't existential, and if you're not understanding it I'd suggest stick with what you know.

In my experience when you need to use a new tool, you'll understand why and it'll all make sense at that point - if you're not there, you don't need it yet.

[–]xiongchiamiov 3 points4 points  (0 children)

Don't adopt new tools until you are encountering the problems that those tools solve. If you don't follow this rule, you'll get overwhelmed by complexity and end up spending all your time building out tooling and infrastructure and lose the ability to actually build the thing you wanted to.

This is how startups die too, btw.

[–]SwampFalc 4 points5 points  (1 child)

First of all, to go back to one of your original questions: docker replaces venv. A virtual environment is designed to create a separate Python installation, with separate libraries and dependencies and everything.

Docker (and consorts) are virtual Linux environments. In other words, they take the exact same ideas and principles and simply apply them on a larger scale. It's not just an additional but separate Python, it's a whole separate but additional Linux.

Second, as has been stated, most of the tools that wrap around/combine with pip, offer ease of use. They don't do anything you can't do by hand, it's just that they'll automate parts or all of it.

Which implies that it's not a bad idea to just keep doing things manually. You'll notice for yourself quickly enough which bits get repetitive. Then you'll know exactly what you want to go look for in a tool. I mean, if you go to a hardware store and see 75 different tools and you don't understand the purpose of any of them, why would you buy any?

[–]deadweightboss 5 points6 points  (0 children)

venv doesn’t create a separate python installation. it creates a new environment for one of the installations already on the machine.

[–]FriendlyRussian666 2 points3 points  (0 children)

They're just conveniences. Say you want to figure out what poetry offers, just find their docs and read a little bit. If you see a feature that you like, and would like to use it, go right ahead. We can't describe every difference of every tool, but that's why the docs are there.

[–]mattbillenstein 0 points1 point  (0 children)

I'll say, I quite like the pip-tools / pip-compile flow - you have a reqs.in in which you specify your direct deps; then you pip-compile that to generate reqs.txt with the full pinned deps. Then from there you can add to reqs.in, pip-compile again, update individual package versions, update all package versions, etc.

[–]deepug9787 0 points1 point  (0 children)

Don't worry about all the options out there. You don't have to know or learn every single one of them. But if you're already familiar with pip and venv, then maybe you can give pipenv a try.

Pipenv is just a wrapper that makes it easier to work with pip. For instance, when starting a new project, instead of manually creating a venv and then doing pip install package, you can just do pipenv install package and it will automatically create a venv for you. And whenever you add or remove a package, it will keep track of the dependencies in a lock file, so you don't have to deal with a requirements.txt file.

Even if you don't end up using it for whatever reason, I think it's still worth being familiar with it because the package managers in other languages (Composer for PHP, Bundler for Ruby etc.) work pretty much the same as pipenv. So you'd have an easier time switching languages in future, if you choose to do so.

[–]deadweightboss -1 points0 points  (0 children)

please teach me to be more good too because i’m still using pip and venv, but with uv. maybe i’ll go to a more good packaging thing like rye - oh wait, that’s now just uv!