Live data from Hacker News

Pyenv – lets you easily switch between multiple versions of Python

github.com

321–330 of 341 posts

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

#321

Earlier quoted context omitted.

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.

> but such advice is why so many beginners have painful Python experience

Sample of one, but I never encountered anything even broken in MacPorts. They seem to embrace the BSD ethos of doing everything right (even if at a slower pace, as some packages lag a few releases behind Homebrew).

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

#322

Earlier quoted context omitted.

> For a beginner trying to run someone else's Python project, it is free. Its absolutely, by far, the highest friction alternative on Windows for anyone that doesn't use Docker for other purposes.

- Not if you have to edit the code. Try to explain your beginner with notepad++ how to do that. - Not if you have to deploy the code. - Not if you have to import the code in your own project. Basically, not if you want to do anything by running the code. For which I would suggest an installer instead.

I don't see what editing has to do with this. Whether you're running the main.py or the Dockerfile, if you want to edit the code then you gotta use Notepad.

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

#323

Earlier quoted context omitted.

Personally I've had problems with poetry managing virtualenvs in the past so I just don't let it touch them any more. Maybe it's better now, but I don't see any reason to risk it, given how often Python seems to like to ruin my day. I also don't like that by default it wants you to use `poetry run` to run things. Sure you can configure it not to, but it still annoys me

One issue I’ve been encountering is that Poetry isn’t aware of pyenv or `.python-version`. So what I do to initially build my venv is: pyenv exec pip install poetry && pyenv exec poetry install This creates the venv against the correct Python version, and I can now do without `pyenv exec` for this repository. And every time that `.python-version` changes (which I at most do a few times per year per project,) I throw…

[deleted]

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

#324
post #303

Earlier quoted context omitted.

One issue I’ve been encountering is that Poetry isn’t aware of pyenv or `.python-version`. So what I do to initially build my venv is: pyenv exec pip install poetry && pyenv exec poetry install This creates the venv against the correct Python version, and I can now do without `pyenv exec` for this repository. And every time that `.python-version` changes (which I at most do a few times per year per project,) I throw…

Now you have poetry installed for every version of python and need to keep track of updating all of those poetry installs. Python really makes things difficult :D

> Now you […] need to keep track of updating all of those poetry installs.

You’re absolutely right.

On second thought, I guess I only need these Poetry installs just once anyway: for creating the venv and then never again. That’s not worth it.

So here’s a new method that does away with these extra Poetry installs:

    pyenv exec python -m venv .venv && poetry install
assuming that a `poetry.toml` exists with `virtualenvs.in-project` set to `true`.

Going to adopt this variant from now on, I guess. Thank you for your thoughts!

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

#325

Earlier quoted context omitted.

I modified my bash prompt to detect and auto-activate Python environments, and show if one is currently active. Haven’t thought about activate in years. It’s great.

Yes, I did that on my work laptop with fish, since I only ever used it with the work project. On my personal machine I don't bother with venvs, so also haven't thought about it in years. But was trying to figure out what the "workon" command did for GP.

`workon` lists all virtualenvs you have in your virtualenvs folder and `workon foo` activates environment foo

this way I have all my envs in ~/virtual and all my projects in ~/projects and just `workon xyz` when I want to be in a certain venv for a given project (which doesn't always map one-to-one)

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

#326

Earlier quoted context omitted.

by compiling from source? god no. also it's terribly named because it conflates the idea of python environments with python versions just install pre-compiled python from official sources side-by-side. no pyenv needed

But that’s the point of the tool. Let it manage that for you.

right, but now you know even less about your setup when you some roadblock. and compiling python from source is very slow and error prone because it requires a bunch of flags and other libraries to be available. I have no problem compiling stuff from source generally, but python specifically is a major PITA

and I already have homebrew to install python (and anything else), which I trust to have more users and better formulas. other OSes have their own tools

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

#327

Earlier quoted context omitted.

How exactly? Isn't a requirements.txt file, generated from pip-compile, incapable of specifying OS stuff? It's also my understanding that pip-tools does not let you make layered requirements files with pyproject.toml files, only with .in files

You can specify different dependencies in pyproject.toml and then use --extra with pip-compile to pull them in. I do this with dev and test sections for example. Constraints seem like they work like you'd expect here. pip-compile also has the -c flag if you want to use that. I guess I don't know what you mean by OS stuff, but maybe this works for that too?

Hmm. So you generate a requirements.txt and a dev-requirements.txt. It sounds like they have overlapping dependencies? I can't get them to be "layered" where the dev-requirements.txt only has the dev dependencies.

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

#328
post #315

Earlier quoted context omitted.

This is more like: - Doctor, it hurts when I hit my head on the wall - Then don't hit your head on the wall You have solutions available, use them

Apparently, “sometimes you don’t have a choice” is a foreign language. — Hey, so you know how we have this requirement, which came about after years of dealing with and understanding a problem and the available solutions? — Yes, what about it? — Well, a random commenter on Hacker News who has zero context of the problem has suggested we use a method we already found inadequate for our specific use case. — Oh wow, in…

I think people are really looking for some examples of scenarios where this might be a requirement and your time might be better spent providing one vs. fighting with them. Maybe something like an airgapped gov network with very specific approved and audited software?

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

#329

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…

Why does it compile Python on your machine?

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

#330
post #25

Earlier quoted context omitted.

Actually, it only builds it locally if it can't find a pre-packaged version for your system/arch. Admittedly that's most of the recent ones on a Mac, but there is a difference (I've been using pyenv for nearly ten years[1] now). The big advantage for me is that I can match whatever runtime and standard library a target has (and yes, that's needed more times than not, even in this new age of Docker). Additionally, you…

Currently going through this myself on a new mac I bought lol. Still haven't gotten anywhere. Oh well $ PYTHON_CONFIGURE_OPTS='--disable-ipv6 --enable-optimizations --with-lto' PYTHON_CFLAGS='-march=native -mtune=native' pyenv install 3.12.2 python-build: use openssl@3 from homebrew python-build: use readline from homebrew Downloading Python-3.12.2.tar.xz... -> https://www.python.org/ftp/python/3.12.2/Python-3.12.2.t…

  PYTHON_CONFIGURE_OPTS='--disable-ipv6
LOL, the strategy of disabling ipv6 even finds its way into Python builds
Post reply on HN