Live data from Hacker News

Pyenv – lets you easily switch between multiple versions of Python

github.com

261–270 of 341 posts

Re: Pyenv – lets you easily switch between multiple versions of Python

#261

Pls dont. Just install several pythons with different binary names. ex. python3.8, python3.9, python3.11 No need to complicate things. If using Poetry, you can just do `poetry env use python3.8`.

What do you do when (not if) your system package manager eventually drops that Python version from their core repositories?

The good thing about pyenv is that it makes you rely less on package maintainers. You can come back to your Python project 10 years later and have a real chance that it still works, even if you have changed workstations in between.

Re: Pyenv – lets you easily switch between multiple versions of Python

#262

Earlier quoted context omitted.

download python 2.7 and run it? no pyenv needed

2.7 has been EOL for five years. It doesn’t get security updates nor bug fixes.

Python Foundation support ended that long ago, but vendors maintained it for longer. Red Hat support for it through RHEL 7 ends 30 June 2024, however, and my guess is they’re the last ones.

Re: Pyenv – lets you easily switch between multiple versions of Python

#263

Earlier quoted context omitted.

This is not true. Nix actually solves the problem. If you package with Nix, you'll get the exact same version of Python with the exact same version of dependencies, including the exact same version of system libraries. Your build will work in a year just as it does today. You don't even need to keep any binary artifacts. Of course this doesn't come free: packaging with Nix may involve nontrivial effort for some proje…

How does nix solves the problem of Python dependencies not specifying their dependencies well or exhaustively? Do you have to find them out and fix them manually or can you generate a lock file and hope for the best?

It depends. If the dependency is in nixpkgs (Nix' own package repository), someone will have done the work of figuring out the dependencies properly and you can just use that. If it's not, you can either do that yourself and pin particular versions, or you can integrate with a tool like Poetry: Poetry could generate a lockfile for you that you then reference from Nix to get the versions of Python packages. You'd still need to specify any native dependencies manually, though.

Re: Pyenv – lets you easily switch between multiple versions of Python

#264

Tools you can use to make sure the Python program you wrote keeps working: requirements.txt, pip, pipenv, pyenv, virtualenv, pyenv-virtualenv, virtualenvwrapper, pyenv-virtualenvwrapper, venv, pyvenv, conda, miniconda, poetry, docker, nix. Which ones did I miss? Which of them actually ensure your program always works the same as when you first wrote it, without asterisks?

pyenv is all you need. pip is part of python. requirements.txt is just a convention used to store the list of stuff to hand to pip.

Re: Pyenv – lets you easily switch between multiple versions of Python

#265

I have to warn again users that think they have found the silver bullet that pyenv comes with a big caveat: it compiles python on your machine. The number of possible modes of failure in this situation is huge. See also: "Why not tell people to "simply" use pyenv, poetry or anaconda" https://www.bitecode.dev/p/why-not-tell-people-to-simply-use I'm not saying pyenv is not a useful tool, but it is not a tool for beginn…

Can I ask - why the dislike for virtualenvwrapper? If you are saying that it can have occasional problems, I agree with you. But it makes the process so much simpler. The occasional problems I’ve had (had an issue once or twice deleting a venv) pales in comparison to the advantage I get in remembering a couple fast commands. Is there something better or am I relegated to “source what/directory/was/it/again/bin/activate?

Re: Pyenv – lets you easily switch between multiple versions of Python

#266

Earlier quoted context omitted.

For managing versions of Python packages, I take a similar route and keep it simple: python -m venv .venv source .venv/bin/activate pip install -r requirements.txt However, pyenv addresses a different problem: managing versions of Python itself. For example, if you need the latest version of Python and it is not available through your OS: pyenv install 3.12 pyenv global 3.12

on Mac OS I just do brew install python@3.8 brew install python@3.12 and pick whichever one I want symlinked as `python` and `python3` (I think the last one you install is the one that gets symlinked, but you could always change those links yourself manually) on Linux it should be just as easy to have multiple versions side-by-side it's been a while since I've done something similar on Windows but it's also possible…

Some Linux distros don’t have the latest Python versions in their package repos, but there are definitely other ways to install versions side-by-side.

Re: Pyenv – lets you easily switch between multiple versions of Python

#267

Earlier quoted context omitted.

> Every solution that I know of on Linux requires you to build Python on the machine Unless you need a Python that's not supported by your Linux distribution, you can just use what's available. On macOS, MacPorts provides compiled versions for 3.2 all the way to 3.13, as well as 2.6 and 2.7. Right now, I have 3.8, 3.9, 3.10, 3.11, 3.12, and a 3.13 development build. The fact it's not Linux (or x86) might cause some f…

If you’re lucky enough to be on a Linux system that uses apt some thankless soul maintains a repo called deadsnakes with all these binaries. Fabulous if you’re using any somewhat old version of Python in CI for instance. Yum based systems are SOL as far as I can tell. Build and host your own binary for that. Apk doesn’t have this either IIRC

That's exactly why I don't really on that for Ubuntu though. It's a single point of failure, when I can just use `asdf` to install Python and easily switch between it, automatically if setup correctly on projects.

Re: Pyenv – lets you easily switch between multiple versions of Python

#268

pip+venv mostly work fine for me, but there are some libraries like say numpy/scipy that are heavy so I want to share them across projects instead of installing multiple copies. I use pyenv to create a python version separate from the system version and install global dependencies into that. It's been useful for that and is just a nice way to manage multiple versions of python. So pyenv is a great addition to the tra…

> I've resorted to making an "actual_requirements.txt" file manually listing only direct dependencies and whatever version constraints make sense.

Pip-tools has an elegant solution for this. You write an requirements.in where you list packages and optionally versions, then pip-compile turns that into a requirements.txt with every package including dependencies specified by versions. You can use it to update specific packages as well.

Re: Pyenv – lets you easily switch between multiple versions of Python

#270

Tools you can use to make sure the Python program you wrote keeps working: requirements.txt, pip, pipenv, pyenv, virtualenv, pyenv-virtualenv, virtualenvwrapper, pyenv-virtualenvwrapper, venv, pyvenv, conda, miniconda, poetry, docker, nix. Which ones did I miss? Which of them actually ensure your program always works the same as when you first wrote it, without asterisks?

You missed Pipenv :-)

Edit: Oh I see you didn't. I can't read.

Post reply on HN