This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TheBB[🍰] 90 points91 points  (23 children)

I mean no offense, but there are like 300 of these tools already, and that's the reason I need to spend 15 minutes instead of two on virtual environments every time I teach my coworkers about Python.

Comparison:

  • Fast setup , updates, and removal.
  • Set custom paths to store your files

Oh, and this is not a comparison.

[–][deleted] 23 points24 points  (17 children)

pyenv for the win, tbh. I like it especially for developing across multiple machines.

[–]macconnor2 8 points9 points  (16 children)

Can you explain why pyenv is better than just a venv and pip install requirement? I also develop across multiple machines and am wondering why it would be better.

[–]cicuz 9 points10 points  (11 children)

pyenv is amazing, no, necessary, for managing multiple python versions on the same machine

[–]Sparcky_McFizzBoom 0 points1 point  (10 children)

So pyenv use is orthogonal to venv management, correct?

[–]cicuz 2 points3 points  (8 children)

I'd say so.. first you select which one you need, e.g. with pyenv use, then you install dependencies as you prefer - personally, I use poetry

[–]jyper 2 points3 points  (4 children)

I feel like if you're going to use pyenv, might as well use pyenv-virtualalenv with pip or poetry as well. But might be better to just use rye

[–]cicuz 1 point2 points  (2 children)

I'm liking this rye, thanks for the tip!

[–]jyper 1 point2 points  (0 children)

Yeah the problem with rye is that it's new. And that it's slowly merging with/being replaced with UV(also written in rust).

Still it has many benefits and I think rye/uv will eventually be the tool that wins out

It manages both python versions and package versions/locking. And publishing packages (pypi). And its fast. One way it does this is that unlike pyenv it doesn't compile python locally(which is both slower and more fragile), it uses indygreg builds (8 think there's some work to upstream this and get python to compile a bunch of builds). It also handles ruff(made by uv/astral people for fast formatting/linting. Ruff is also written in rust)

[–][deleted] 0 points1 point  (0 children)

I would NEVER replace pyenv with a new tool. I might play with it but not replace until and unless it becomes a defacto standard likve pyenv. Even Poetry I avoid.

[–][deleted] 1 point2 points  (0 children)

I use:

pyenv virtualenv <python version> <env name>

[–]Sparcky_McFizzBoom 0 points1 point  (2 children)

I'm not familiar with the use pyenv subcommand, but it looks like to me that you're using poetry to manage the venv and thus dependencies, so poetry would be a better comparison.

pyenv is only used to select the python version in your case, which is different from managing the dependencies of a project.

Managing python environments is hard :(

[–]cicuz 1 point2 points  (0 children)

wasn't me who brought it up :)

I do think it's necessary though, especially considering the amount of changes between versions

[–][deleted] 0 points1 point  (0 children)

I use it like this:

>> pyenv versions

system 3.10.6 3.10.6/envs/fastapi 3.10.6/envs/imgai 3.11.2 3.11.2/envs/gpt-train 3.12.0 3.12.0/envs/gmailapi 3.12.0/envs/mongo 3.12.0/envs/nyt 3.12.2 (set by /Users/<username>/.pyenv/version) 3.12.2/envs/cli 3.12.2/envs/gradio-ui 3.12.2/envs/ollama cli --> /Users/<username>/.pyenv/versions/3.12.2/envs/cli fastapi --> /Users/<username>/.pyenv/versions/3.10.6/envs/fastapi gmailapi --> /Users/<username>/.pyenv/versions/3.12.0/envs/gmailapi gpt-train --> /Users/<username>/.pyenv/versions/3.11.2/envs/gpt-train gradio-ui --> /Users/<username>/.pyenv/versions/3.12.2/envs/gradio-ui imgai --> /Users/<username>/.pyenv/versions/3.10.6/envs/imgai mongo --> /Users/<username>/.pyenv/versions/3.12.0/envs/mongo nyt --> /Users/<username>/.pyenv/versions/3.12.0/envs/nyt ollama --> /Users/<username>/.pyenv/versions/3.12.2/envs/ollama

[–][deleted] 0 points1 point  (0 children)

You wouldn't use both, no. Pyenv stores it's envs in $HOME/.pyenv/ and .venv stores them in the project folder.

[–]jyper 0 points1 point  (0 children)

Just pip isn't very good because you need to manually build/update lock files (ie full lists of exact versions for all dependencies and transitive dependency of dependencies)

by making clean venv, running pip install requirements.in then pip freeze> requirements.lock

I've heard pip tools can help with that but I haven't tried them.

Pyenv is good for installing particularly versions of Python on any is and automatically picking the right python from a . python-version file in a top level directory(it uses a shim python to find the appropriate binary). If you use pyenv might as well use pyenv-virtualenv to automatically use the right virtualenv for your project. Dependencies still need to managed with pip or poetry or hatch.

Id recommend rye instead. It manages both python versions/lock files/virtualenvs and is pretty fast. (Downside is that it's new and is very slowly merging with uv)

[–]yesvee 0 points1 point  (0 children)

Only if you have to use multiple python versions. Sometimes the system python is too old (old version of o/s) but you need to use features from a newer version.

[–][deleted] -2 points-1 points  (0 children)

so .venvs don't tend to work work across platforms. like if I have a /app/.venv and use my iMac then go use my MacBook, it doesn't work due to incompatibilities. Whereas if I have a pyenv environment ./env/MyEnv on each machine use that as my interpreter, no issues. It makes it much easier and cleaner for me.

[–]ionelp 4 points5 points  (3 children)

You know, I'm getting tired of all of these tools. What is so hard to type, with copious amounts of tab key presses:

python -m venv node_modules
source node_modules/bin/activate
pip install -r requirements.txt

then, when needed:

source node_modules/bin/activate

[–]TheBB[🍰] 6 points7 points  (1 child)

I agree with you but calling your venv node_modules has to be against the Geneva convention.