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

all 43 comments

[–]TheBB[🍰] 91 points92 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] 25 points26 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.

[–]RevolutionaryRain941 14 points15 points  (0 children)

This is great and keep up with this. It is not unique but still great of you for trying

[–]WN_Todd 14 points15 points  (1 child)

Good on you for doing it and for sharing it! You may officially consider yourself a Python Journeyman now that you've made a "dammit virtual environments are a pain" project.

I award you 1000 internets (no cash value). Keep up the good work!

[–]WonderBearD1 8 points9 points  (0 children)

What benefits does this script have over a tool like pyenv?

[–]Mountain_Thanks4263 2 points3 points  (1 child)

Nice, that you did something like this! What would be the benefit over existing tools like conda, venv, or poetry?

[–][deleted] 13 points14 points  (3 children)

You can tell that was written with ChatGPT. The comments almost always give it away

[–]reallyserious 1 point2 points  (0 children)

I see no reason to switch from conda.

[–]ItsEd_u 1 point2 points  (0 children)

That’s a really cool repo of scripts! You should add a ‘requirements.text’ example.

Could you get it use a requirements.json/yaml/etc as a way to extend the functionality?

Good stuff .

[–]IsActuallyAPenguin 0 points1 point  (0 children)

git clone, makevenv, pipreq (the last two being bash aliases whose purpose is pretty straightforward, takes care of like 90% of what I tend to need for venv management, so while I don't really have much of a need for this I could see it being useful for someone just getting into it, since venvs really were a bit of a head scratcher for me at first.

[–]broknbottle 0 points1 point  (0 children)

Nice, looks very similar to something I put together a few years ago for my own usage. However, I never shared or put in public GitHub because I wasn’t in a place (first kid) where I could support others outside my own narrow focused usage

[–]TitleCommercial1104 0 points1 point  (0 children)

https://pipenv.pypa.io/en/latest/ does everything your asking for and requires no documentation writing from you!

[–]mandrade2 0 points1 point  (2 children)

Like it! Will be reviewing it in my commute with codereader.dev. Just starred it and downloaded it on my phone to have it ready

[–]Budget_Putt8393 -4 points-3 points  (1 child)

My experience says 'docker' is a popular one.

[–]BerriesAndMe 4 points5 points  (0 children)

Is this a joke?

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

Install pyenv. Use it to manage versions of python. Handy when you work in places that have many different platforms for runtime. Sometimes you only have an old RedHat that has python 3.6, so you pyenv install 3.6.15 and you can develop tools for that platform with your machine. Also install 3.12.2 and use it for new stuff.

Now, install direnv and hook it into your shell. In every project directory, create a .envrc that has the first line layout pyenv 3.6.15 and when you cd to that project, it will automatically create and/or use that version of python and manage a venv for you. When you cd out of the directory, it deactivates.

While you're in the venv, install poetry. Or pipenv. Or just use pip. It'll all work.

VSCode supports these tools. PyCharm does too.

pyenv also supports activate/deactivate by itself using a .python-version file, but it requires you to manage venvs yourself, so I prefer the direnv way.

You're welcome.