Live data from Hacker News

Pyenv – lets you easily switch between multiple versions of Python

github.com

211–220 of 341 posts

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

#211

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…

I have not suffered any issues due to pyenv compiling. In our prod boxes we compile Python ourselves anyway. It's a really trivial build process tbh.

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

#213
post #179

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…

If you don’t care which specific version of python you are using, do not use pyenv. You will know when you care. These days, doing common tasks, the constraint solver in poetry will often tell you: “Hey! I can’t find a version of sentencepiece with metadata that lets me combine this with python 3.12.2. Sorry! I give up!” Now, if you aren’t concerned with using your bare metal for CUDA or fancy new MPS or AMD stuff. J…

This kind of error surprises me:

> I can’t find a version of sentencepiece with metadata that lets me combine this with python 3.12.2

I'm a reasonably advanced python user. I've shipped web apps, Desktop GUIs, cli-tools, and even written cpython extension modules for custom hardware control. I typically target the system `python3` of whatever linux distribution I'm shipping to and I use the system 'python3-virtualenv' for venvs.

But I have never encountered a dependency resolution issue or been forced to use poetry. What am I doing wrong?

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

#214

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 only need pip and virtualenvwrapper requirements.txt is a text file, not a separate tool... if you want your program to work exactly as intended in the future, there are tools like py2exe and py2app for that.

Don't need any wrappers either. venv has been built into python for ages.

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

#215

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…

So, what is "the tool for beginners fighting with python packaging problems"? That is, the pattern seems to be that someone mentions a solution, then a zillion responses as to why it sucks. Is there any tool or pair that sucks least for most cases and beginners? I get that every case is different, but perhaps there are some useful starting points?

While there are no silver bullet, for beginners, I found that "Relieving your Python packaging pain" (https://www.bitecode.dev/p/relieving-your-python-packaging-p...) is the Pareto solution. That is, the solution that has the best ratio of effort, reward, but also the lower risk of failure. It's not no risk, but I've been helping beginners for 15 years with Python, and have tried everything you can think of.

It does imply, on linux, to limit yourself to the choices of Python you can install. This constraint is, for most people, preferable than the alternative, even if it gets frustrating to our geeky soul.

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

#216

Earlier quoted context omitted.

What package managers are people using in other languages to make sure that software "always works the same as when you first wrote it, without asterisks"? I'd like to understand how they solve the "package no longer exists in a central registry" problem.

Dotnet uses Nuget[1]. Packages in the system are immutable, & never changing. They can be unlisted, but never deleted (except in limited & extreme cases, like malware), which means even if a package maintainer stops publishing new versions to the repository, existing packages will continue to be publicly available for as long as Microsoft continues to exist. [1] https://www.nuget.org/

Often a package says it works with OS version X, and not X+1. It may be true or false. But what you described does not solve either version of that problem.

Or the "says it will work with > X," but doesn't.

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

#217
post #78

Earlier quoted context omitted.

> but a python venv does make sure you're using the same runtime. It does not. > There are symlinks in the environments bin directory to the specific runtime. Precisely. They symlink to a path . Which means that if you have a certain version of Python at one location (let’s say /usr/bin/python3) and later update that (let’s say by upgrading macOS and the Xcode developer tools), the same virtual environment will point…

This is not the way you're supposed to be using pyenv You're supposed to install a specific version of python in a specific place, with a specific name. Say, /usr/local/python-3.10.6 Use pyenv to use that python. Control that by creating a `.python-version` file that says 3.10.6 You now have a project that uses 3.10.6. Unless, of course, somebody installs a different version in that path - at which point you've got b…

> This is not the way you're supposed to be using pyenv

Because that’s not what the conversation is about. It’s about virtual environments.

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

#218

Earlier quoted context omitted.

For now most people would do well to stick to python.org installers for mac and windows. For linux, official repos are ideal. If you really, really can't (which is different than wanting to), ubuntu deadsnake and red hat epl are the best second plan, while already more finicky. If you use something more exotic, you chose hardship, and you will have to be up to the task. Anything else will come with bigger caveats tha…

Even on Macs, you can use MacPorts. They provide a lot of versions pre-compiled (and everything is BSD-solid).

I know you mean well, but such advice is why so many beginners have painful Python experience.

Macports and homebrew Pythons are dependencies of other packages. They can be used by you, but they are not meant for you.

This means at some point, they will contain a surprise, and not a good one.

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

#219
post #96
post #78

Earlier quoted context omitted.

> but a python venv does make sure you're using the same runtime. It does not. > There are symlinks in the environments bin directory to the specific runtime. Precisely. They symlink to a path . Which means that if you have a certain version of Python at one location (let’s say /usr/bin/python3) and later update that (let’s say by upgrading macOS and the Xcode developer tools), the same virtual environment will point…

You can use --copies if you don't want symlinks [0]. [0]: https://docs.python.org/3/library/venv.html

Not with the macOS Python from the Xcode developer tools:

> Error: This build of python cannot create venvs without using symlinks

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

#220

Earlier quoted context omitted.

asdf can be used as an alternative to pyenv. (In fact, it is not only meant for the Python ecosystem, so it can also replace nvm and others.) For me, the combination of asdf and Poetry has worked quite well recently: I use asdf to pin the Python & Poetry version and then use Poetry to pin everything else.

Point of clarification: asdf uses python-build which is from pyenv. https://github.com/asdf-community/asdf-python?tab=readme-ov-...

True. I mentioned asdf mainly because it can be used with many languages & tools and is not restricted to the Python ecosystem.
Post reply on HN