Live data from Hacker News

Pyenv – lets you easily switch between multiple versions of Python

github.com

221–230 of 341 posts

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

#221

Earlier quoted context omitted.

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.

yes but `workon` is too good not to have

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

#223
post #23

Earlier quoted context omitted.

These builds are an alternative: https://github.com/indygreg/python-build-standalone Those are what Rye and hatch use. Drawbacks: late availability of patch versions, various quirks from how they are built (missing readline, missing some build info that self-compiled C python modules might need.)

I think PEP711 ( https://peps.python.org/pep-0711/ ) is (eventually) a better alternative, because it builds on top of the proven manylinux approach to binary compatibility.

Very cool, this is the first time I'm hearing of PEP 711! I hope this (or some other PEP like it) will get accepted eventually!

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

#224

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

The thankless soul is the awesome Anthony Sottile, who is also the author of pre-commit.ci: https://twitter.com/codewithanthony

Drop by and send thanks cause he really needs them.

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

#225
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…

The binary installs aren't that generic in the machines I've used (mac and debian based, so covers a fair bit). It's python3.11, not python3, and the python3 "executable" is, itself a symlink to the particular binary (in this example python3.11). Upgrading just changes the symlink, which wouldn't affect the venv, which isn't using python3, it's using python3.11. I didn't introduce anything, I explained how the links…

> It's python3.11, not python3, and the python3 "executable" is, itself a symlink to the particular binary (in this example python3.11).

Not for the example I gave. If you’re seeing Python 3.11, you’re definitely not using the /usr/bin/python3 on macOS with is made available by the Xcode CLI tools. That’s at 3.9.6 even on Sonoma.

> as someone else also points out, you don't even have to use the symlinked versions, you can use --copies

Which, again, doesn’t work for the stated case.

https://news.ycombinator.com/item?id=39818732

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

#226
post #21

I used to use this a lot when working on a Windows machine. Worked pretty well. But nowadays Nix solves the same problem in a fully general way, for all software rather than a single language. You can have whatever versions of whatever you want, side by side, without interfering with each other.

What is your solution here? Are you using a project-specific flake? Do you still install packages with pip?

I was more talking about version management of the Python interpreter itself. So far all the packages I need are already in nixpkgs so I haven't needed to stray off that path yet.

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

#227

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…

Oh man, you just confirm that I’m not crazy. For every single time I use pyenv it just downloads source and build. I got tangled into so many issues such as TLS headers in my AL2 boxes. I thought the whole thing is about getting the official binary and install and not compile from source even for a 2 year old release.

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

#228
post #146

Earlier quoted context omitted.

That happens way more often than people want to admit, and I think it's not genuine to present the tool that way. E.G, I'm on Ubuntu 20.04 on an Dell XPS, a fairly standard machine, I'll get: pyenv install 3.9 -v /tmp/python-build.20240325124651.73089 ~ Downloading Python-3.9.19.tar.xz... -> https://www.python.org/ftp/python/3.9.19/Python-3.9.19.tar.xz ... LD_LIBRARY_PATH=/tmp/python-build.20240325124651.73089/Python…

Actually, I'm pretty sure that binaries for Python 3.9 aren't available on Ubuntu 20.04 without adding an apt repository to get them from, so your statement that you "can apt install it" isn't entirely correct in this case - by default, binaries aren't available, and therefore pyenv has to compile Python 3.9.

Just tried, I get the same result with 3.7, 3.8, 3.10 and 3.11.

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

#229
post #23

Earlier quoted context omitted.

These builds are an alternative: https://github.com/indygreg/python-build-standalone Those are what Rye and hatch use. Drawbacks: late availability of patch versions, various quirks from how they are built (missing readline, missing some build info that self-compiled C python modules might need.)

I think PEP711 ( https://peps.python.org/pep-0711/ ) is (eventually) a better alternative, because it builds on top of the proven manylinux approach to binary compatibility.

I hope this will be merged with indygreg builds at some point, but the community move slowly on those issues so it may take years.

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

#230

Earlier quoted context omitted.

None. The software container image is the best bet but you need to keep the image and not only the building scripts.

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?
Post reply on HN