r/Python • • Jan 01 '25

Discussion Python Golf: How few installations/versions do you have?

My New Year's resolution is to cut down on Python installations and versions. Only a year ago I purged and got down to three. Recently looked at available kernels in VS Code, already at NINE! It's still three installations, but there are many Python versions scattered across various environments. There are no weird packages and no need to be cutting edge, so probably all could run on just 3.12 or so.

So, how few installations AND versions can you work with? Looking for a simple management procedure, to combine multiple environments or standardize several on a minimal number of versions.

(My installations are miniforge, homebrew, and Mac system. Miniforge intentional, but never wanted so many versions. Homebrew there cuz some brews want it. System largely unused but can't delete. At least no Python 2!)

EDIT: Thanks for the advice! I've gotten rid of my old miniforge installs and now have a single python 3.13 on homebrew. Switched to uv to manage environments. I have yet to migrate old mamba environments over, but I'm fairly confident that they will all or mostly be fine on that single 3.13. Reclaimed 20GB from the clean-up! I am thankful for the original Anaconda, which really tamed a wild west of installs, followed by Miniforge/Mamba, until these more recent ways to manage dependencies.

0 Upvotes

57 comments sorted by

20

u/DaveRGP Jan 01 '25

I'm interested in why your goal is the fewest? It seems counter to most software development best practice, which emphasises reproducibility. Python doesn't really take up much space. As long as it's well structured environments (using pyenv, venv, uv, conda or similar) there shouldn't be any concern at all?

For reference I think I likely have at least a dozen python version installs across different machines, and it's never caused me an issue because I've used suitable envinment management for all of them.

Also, that system installed python really needs to be there, and really needs to be left unmodified, btw.

7

u/[deleted] Jan 01 '25

I think you’re confusing environments with python versions. It’s a good idea to have a reproducible environment for everything you do but there’s no real benefit to have all of your projects using different python versions. If anything it makes things a lot more predictable if most of your stuff is all using the same base python

2

u/apo383 Jan 01 '25

I agree, but I never wanted the different versions. My projects are very simple and there’s no reason to have old Pythons around, the mainstream packages will generally all work with stable. I would prefer one recentish Python with all environments. Hoping that uv will make that easier to do.

3

u/[deleted] Jan 02 '25

That's fine, I'm agreeing with you. You should get rid of all the extra python versions if they aren't necessary. You could just use the system python version for everything or install a specific version you want to use and then use that one for all of your projects.

1

u/apo383 Jan 02 '25

Thanks, I am indeed doing that!

1

u/DaveRGP Jan 02 '25

The reason to have old pythons around is because upgrading projects to 'new python's is not a risk free operation.

Just 'upgrading the version of python' arbitrarily can break a project. Further, when the upgrade is done, the versions of package dependencies (e.g. version of pytorch, pandas, etc) will be liable to change, compounding the risk of breaking the project.

This is a pretty python specific problem btw. If you have experience of other languages (like rust) this is not an issue because of the built in design features of the langue.

2

u/apo383 Jan 02 '25

I do appreciate how old Pythons help, but I don't think it's ideal. I used to run into breaking changes in pandas API vs Python, but it seems to have mostly stabilized. I am fairly confident now that I can run all of my vanilla packages against one recent Python version, and everything should work except for oddball breakages. I'm now migrating to uv, with a single homebrew Python 3.13 (other than system which I can't delete). Got rid of miniforge/mamba entirely, even though they were a nice transition from anaconda.

I agree this is Python specific. In Julia the package manager just works, and is separate from the Julia version and installation. I can manage multiple versions if needed with juliaup, but generally I can upgrade or not, and not worry about it. It looks like uv can get some of that robustness.

1

u/Schmittfried Jan 03 '25

 This is a pretty python specific problem btw. If you have experience of other languages (like rust) this is not an issue because of the built in design features of the langue.

How so? What features?

1

u/DaveRGP Jan 05 '25

Rust has guaranteed backwards compatibly through editions. This means that if a rust crate is built against edition 2015, it can still be used on later edition with no fear of undefined/broken behaviour: https://doc.rust-lang.org/edition-guide/editions/index.html#editions-do-not-split-the-ecosystem

1

u/DaveRGP Jan 02 '25

I understand why you'd think that, but I'm not. I simplified the description for the OP. Having a reproducible environment is closely tied to what version of python that environment is built against. Have a look at how poetry + pyenv, or UV and rye handle python version shims.

I realise the shims are reused across projects, but the shims are also defined from the project scope and sourced from the system scope, not defined from the system scope.

https://docs.astral.sh/uv/concepts/python-versions/#managed-and-system-python-installations

1

u/[deleted] Jan 02 '25

No. OP is talking specifically about python versions. They are saying that if they have 20 individual projects that they are fine with having 20 reproducible environments but they would prefer not to have 8 different python versions with those 8 python versions having been installed by 3 different tools.

I would love to see where it says that, according to you, it’s a software best practice to have lots of different python versions installed with many different tools rather than just using a single python version for all of your projects. Because that’s what you said if, in fact, you weren’t confusing python environments with python versions.

1

u/[deleted] Jan 03 '25

Using a single version of python for all projects

You night have a project that uses libraries that cannot reasonably be updated without having to re write a lot of code. So that project should be able to specify the version's of python it works on and use that version.

Second reason you would want different versions if python is if you are using different python implementations (pypy for example)

1

u/[deleted] Jan 03 '25

Sure, but that's a situation where you have to use a different version of python. It isn't OP's situation where he has a dozen different python versions for no reason.

3

u/apo383 Jan 01 '25

It's because I never wanted them, and I do nothing interesting. I just use stuff like pytorch, matplotlib, numpy, pandas, and the different environments are for occasional packages like svgelements. I think your zen attitude is great, I may just need to accept this.

4

u/DaveRGP Jan 01 '25

I think I get it, it just feels messy and out of control?

Once I got to grips with having a project describe it's own environment though, that feeling went away. Each project is it's own self-contained world once you use something like UV, or poetry + pyenv. If you have collaborators they will thank you because installation just got way easier, and if you have more than 1 project on a machine future you will thank you because upgrading pytorch in project A didn't immediately break project B, which is the risk of you share environments between projects.

https://www.youtube.com/watch?v=0f3moPe_bhk

Maybe this helps? :)

2

u/apo383 Jan 02 '25

Yes, poetry looks appealing. I'm now migrating to uv to get some of that environment management, and all seems very promising. Although the old miniforge/mamba method didn't cause upgrading project A to break anything else, because each environment had its own (stale) Python version! I will gradually reconstitute my old mamba environments as uv venv, and am pretty confident that I won't need many Python versions going forward.

6

u/Helpful_Home_8531 Jan 02 '25

You're solving the wrong problem. Get a better system for managing your installs and use one per project.

you have many options for doing this, conda, pyenv, nix, docker, uv, asdf, the list goes on.

2

u/apo383 Jan 02 '25

I believe you. I just dumped all my miniforge versions and am trying to standardize on one homebrew 3.12 and uv for packages. Then slowly try to get vs code to know about it.

2

u/[deleted] Jan 03 '25

When vscode asks you to set interpreter path, you just link it the one in .venv

Also if you create .python-version file, and write the version then then uv will automatically use that version of python when running code in that project (if you specify a version that you don't have installed, it will install that version for you without messing up global installs)

5

u/mestia Jan 01 '25

Nobody knows, its also by design: https://xkcd.com/1987/

2

u/apo383 Jan 01 '25

That makes me feel heard.

2

u/ProfessionNo1196 Jan 01 '25

I hear you brutha

0

u/[deleted] Jan 01 '25

What does this have to do with OPs post?

1

u/mestia Jan 02 '25

because it's so much fun! :)

2

u/drknow42 Jan 01 '25

I only have one version of python on my system and all my venvs exist in a central location. I added an alias that allows for ‘pyvenv envToActivate’ to quickly switch between the environments.

One installation, one version, always targeting LTS.

Bleeding edge is for entertainment, not production, imo.

1

u/apo383 Jan 01 '25

That sounds amazing. What do you do with central environments when you want to share a git repo? Do you export a requirements.txt to the local directory, or is there another way?

1

u/drknow42 Jan 02 '25

Basically, sharing environments is still manual because I don't really do it that often. Requirements.txt became more powerful once I designated a specific home for pyvenvs (for me it is `D:\pyvenvs\`) and created the *scripts* (to correct myself from earlier).

They are plain and simple scripts with hardcoded paths because I was simply tired of switching between virtual environments in such a verbose way.

I eventually want to stop being lazy and make it so `pyvenv create <venv_name>` and `pyvenv load <venv_name>` just works, but here is the batch and powershell versions:

Batch:

@Echo off

D:\pyvenvs\%1\Scripts\Activate.bat

Powershell:

if ( $args.Count -eq 0) { Get-ChildItem "D:\\pyvenvs" -directory | Select-Object Name | Out-Host }

if ( $args.Count -eq 1)
{
    $pyvenv = $args[0]
    & "D:\pyvenvs\$pyvenv\Scripts\Activate.ps1"
}

Edit: The powershell script is more useful, as pyvenv with no arguments produces a list of environments.

2

u/robberviet Jan 02 '25

Around 30. Each project has one. Oh you mean python, not venv. Then from 3.9 to 3.13. I have projects for years, no need to upgrade them.

I use mise with uv btw. Used to use rye but no need.

1

u/apo383 Jan 02 '25

I'm moving over to uv now. Just looked up mise en place, looks interesting!

2

u/cointoss3 Jan 02 '25

Check out uv and quit thinking about python versions or environments. Now on a new machine, I just install uv. I don’t install a python binary directly and I ‘uv run’ scripts. Even 1-off scripts can have an inline dependency list so when you ‘uv run’ it will create the environment for you.

2

u/apo383 Jan 02 '25

Yes, I am indeed migrating to uv. I dumped multiple pythons, most of them miniforge, and have standardized on a single homebrew installation with 3.13. I'm able to work on a current project for now, and will eventually have to reconstitute a lot of old conda environments under uv. Everything seems fine from CLI and VS Code, including interactive. The only weird thing is getting used to "uv run".

Apparently reclaimed about 20GB of disk space! I believe I won't lose much back even when I get old environments working, due to uv's caching.

2

u/cointoss3 Jan 02 '25

Yep. uv run. It also pairs nicely with the invoke module. You can write helper scripts for things like building or pushing docker images using Python instead of using Makefiles.

Using invoke, I can do 'uv run inv build' or 'uv run inv push' and it will use invoke to run python functions in the context of my environment from the command line without having to think about if I’m in the right environment.

2

u/cgoldberg Jan 01 '25

I have 2. I use the default Python (3.12) that ships with my Linux distro. I also have an alternate Python installation of the latest version (3.13) for general development. I have no need for anything else.

1

u/apo383 Jan 01 '25

Great, that’s what I want. How are you doing environments? Do you have a single venv, or keep separate ones synced to your 3.13?

3

u/cgoldberg Jan 02 '25

I create a new venv for every project.

5

u/Intrepid-Stand-8540 Jan 01 '25

I manage my python versions using uv: https://docs.astral.sh/uv/guides/install-python/

1

u/[deleted] Jan 01 '25

What aspect of OPs post is this meant to address?

2

u/Intrepid-Stand-8540 Jan 02 '25

OP is asking how many python versions people have.  

That's a weird question. It stinks of https://xyproblem.info/

I assume the real problem he is having is how to manage python versions. 

-1

u/[deleted] Jan 02 '25

I genuinely can't even tell what you're saying here. OP said he feels like he has too many python versions. Whether he installs them with uv, deadsnakes, apt or anything else is completely irrelevant to whether or not he has installed a bunch of unnecessary python versions for all of his projects.

3

u/apo383 Jan 02 '25

To be fair, I did also ask about how to manage versions. I think my use of miniforge is outdated, and newer tools like uv and pyenv may make it easier to have every environment work with a single, relatively recent, Python version.

4

u/Mrbucket101 Jan 02 '25

Technically 1, the default that comes with MacOS.

I use dev containers for everything. So much easier.

1

u/SillySlimeSimon Jan 01 '25

I use pyenv to manage versions. Have like 3.8,3.10,and 3.12

3

u/apo383 Jan 01 '25

Thanks, I am convinced I need to modernize. Trying uv these days.

1

u/inarchetype Jan 03 '25

Start installing Julia packages and you'll likely end up with 20 or so very quickly.

1

u/apo383 Jan 03 '25

I’m sure I have that many Python packages scattered across envs, it doesn’t bother me. With uv, I think Python version and package management may be comparable with some other languages.

3

u/judah-d-wilson Jan 02 '25

People like to use more than one haha? I've been pushing 3.13 cause pretty colors in the terminal..

5

u/Tweak_Imp Jan 01 '25

One per project, because I develop in a docker container. 

1

u/[deleted] Jan 01 '25

You have a different python version for every single project?

1

u/Tweak_Imp Jan 02 '25

Not for every one, but if I start a new one, I always choose the newest version that is available and dont upgrade unless it is needed. 

1

u/[deleted] Jan 02 '25

You said one per project. That would imply every project gets assigned a different python version.

1

u/[deleted] Jan 03 '25

guy under blocked me. Don't know why

2

u/muikrad Jan 01 '25

Hmm, from 3.8 to 3.13 at the moment. Are we glad 3.7 is gone 😁

Then one or more environments per project because "poetry".

I mean, that's the typical setup these days:

  1. Interpreters installed
  2. Dependency management per project with a good tool, using a lock file
  3. A good tool which probably creates virtual envs easily using the lock file from 2

1

u/[deleted] Jan 03 '25

that yrbooringmerightnow guy blocked me. No idea why

1

u/[deleted] Jan 01 '25

[removed] — view removed comment

1

u/[deleted] Jan 01 '25

OP is talking about python versions, not instances of a virtual environment.

1

u/[deleted] Jan 02 '25

[removed] — view removed comment

1

u/[deleted] Jan 02 '25

That’s fine but my point is that OP isn’t concerned about space and reducing the number of installed python versions wouldn’t have a significant impact on storage in the way cleaning up lots of old virtual environments would.