Live data from Hacker News

Pyenv – lets you easily switch between multiple versions of Python

github.com

251–260 of 341 posts

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

#251

Just use the builtin "python -m venv" and life is good, why the others? I tried almost all of them, with various issues, now staying with the default venv, it's solid and get the job done.

The premise of controlling python version is that - you're sending the project to your friend / colleague and you want both of you to use the same python version so that you get the same behaviour. And then the same for your friend the buildserver. It's all about reproducibility.

which venv does really well, what am I missing.

in the "worst" case you can always do a docker

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

#252

Earlier quoted context omitted.

> Python distribution and packaging is just fundamentally horribly broken It's clearly not because most people successfully use it fine. The problem of distribution and packaging is often a matter of user expectations vs. the actual problem. The user expectations is that Python is a high level language and will run the same across different machines regardless of OS and Hardware. The actual problem is Python is a glu…

I don't disagree with what you're saying but that article seems odd. It's just a story of someone installing something once that didn't break immediately. Not only is it anecdotal, it doesn't even seem to confirm whether the pip story is getting better or if they just got lucky.

I agree, but there is no large scale study on this.

As someone who has managed Python distributions in a large company and who triages issues on the pip github issue page that my anecdotal experience is things are getting better.

The only hard statistic I can point to is the number of top packages on PyPI that offer wheels has substantially gone up, and is close to 100% in the top 500.

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

#253

Earlier quoted context omitted.

> Python distribution and packaging is just fundamentally horribly broken It's clearly not because most people successfully use it fine. The problem of distribution and packaging is often a matter of user expectations vs. the actual problem. The user expectations is that Python is a high level language and will run the same across different machines regardless of OS and Hardware. The actual problem is Python is a glu…

They use it fine by using Docker. So many major Python repos on GitHub come with a Dockerfile compared to, say, NodeJS. It's unfortunate, but having dealt with Python packages before, I don't blame them.

Lots of analysts, data scientists, traders, engineers, etc., use Python third party packages successfully, and have never touched, or maybe even head of, Docker.

And yeah, in general there are significantly less NodeJS third party packages interfacing with packages that directly depend on OSes and hardware. Python has many third party packages that are older than NodeJS that depend on foreign function interfaces, win32 com apis, directly talking to graphics shaders, etc.

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

#254

Earlier quoted context omitted.

Curious what you like about mise! I've been a strong advocate for asdf for a few years now. Aside from smooshing together tools that are often used together, but not always (direnv, make), I can't see what mise adds to the picture. And I like still having direnv for what direnv does and make for make does, rather than an all-in-one.

the asdf CLI has really sharp edges and feels kind of aggressively unhelpful. Even if you just use mise as an asdf alternative, it has a nicer CLI and interacts with the same plugin ecosystem more smoothly. (I've found it to be an improvement on direnv, but I still use make) the comparison to asdf page has more: https://mise.jdx.dev/dev-tools/comparison-to-asdf.html

Damn. I'm convinced. The asdf CLI was always a bit of a pain ... mostly I don't interact with it that often. But mise seems light years better designed. Thanks!

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

#255

Earlier quoted context omitted.

They use it fine by using Docker. So many major Python repos on GitHub come with a Dockerfile compared to, say, NodeJS. It's unfortunate, but having dealt with Python packages before, I don't blame them.

Lots of analysts, data scientists, traders, engineers, etc., use Python third party packages successfully, and have never touched, or maybe even head of, Docker. And yeah, in general there are significantly less NodeJS third party packages interfacing with packages that directly depend on OSes and hardware. Python has many third party packages that are older than NodeJS that depend on foreign function interfaces, win…

Python packages are painful even if nothing native is involved. There are NodeJS packages that rely on native code too, difference is the packaging system is a lot simpler to use, though it's starting to get worse with the `import` vs `require` nonsense and Typescript.

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

#256

Earlier quoted context omitted.

The premise of controlling python version is that - you're sending the project to your friend / colleague and you want both of you to use the same python version so that you get the same behaviour. And then the same for your friend the buildserver. It's all about reproducibility.

which venv does really well, what am I missing. in the "worst" case you can always do a docker

venv only works if you already have the required version of python installed and have it active as the python for your shell (or use a launcher to which you specify the python to use in the command line), since venv just creates a virtual environment based on the version of python it is run with.

So you actually need something that can read a specification of the required python version and use the correct one from the available options (maybe even reaching out and getting it if it isn't already locally available, though I don5 remeber if any of the existing python build tools will do this; docker obviously will, but its not really a python build tool), across different OS flavors (maybe not that last bit, depending on the use case, especially for internal development), and with minimal overhead for the build tool itself.

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

#257
post #87

Earlier quoted context omitted.

Odd to me that you don’t let poetry create the venv? Why do this separately? Our flow is similar: pyenv (windows and linux), pipx, poetry. We’ve also defaulted poetry to utilize the current global version of Python and build the venv within the project folder.

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 away the `.venv`, do `pyenv install -s` and start over.

Your `poetry run` point still stands, though.

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

#258
Was a pyenv user for the longest time, but I switched to Docker containers instead. I put together bash functions that take in a positional argument for the image and port (or randomizes it if not specified), and it automatically mounts the current working directory to the volume. Now I can just start a container without having to think about any of this stuff. And a config file per project if I don't want to pass in any variables at all.

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

#259

This is the way. I moved everyone I work with at over to the pyenv, virtualenv, poetry stack. Once you get set up it’s pretty smooth sailing. It is a shame that so many tools are needed to work with python, but I was happy to finally find something that works.

Curiously, post-checkout, how do you go about creating your venv and installing your project dependencies?

The shortest ritual I could figure out so far is:

    pyenv install -s && pyenv exec pip install poetry && pyenv exec poetry install
and I wonder what might be an easier incantation that still works.

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

#260

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…

Data point: pyenv works just fine for me. It helps me with installing/managing many python versions (multiple years).

I guess, I'm in the "expert" category. I'm saying it so that people won't be afraid to try it.

Post reply on HN