Hacker News new | ask | show | jobs
by pqdbr 702 days ago
For someone that is from the Ruby world and uses rbenv / bundler confortably, what would be the canonical way of using / managing Python in MacOS?

There seems to be a sea of alternatives and I see every tutorial mention `pip install` while I don't even have that running in my CLI (only pip3). Do people assume an alias here of I have somehow messed up my environment?

4 comments

Pixi [1]. A lot of people recommend UV, which pixi uses under the hood to install pip packages [2].

The difference between UV and pixi is that pixi is better tooling for working with Conda repositories, and UV focuses in working with pip packages. Pixi allows installing not only pip packages but anything that has been packaged for Conda, which includes a lot of non-python stuff (C/C++ libraries and more).

For instance, I use it to install the Go compiler per-project, since using a global installation tends to grow "polluted" with every single go package that you have ever installed. You could even use it to install Node, NPM or ruby per-project, it just works. It also supports lock files [3].

--

1: https://pixi.sh/latest/

2: https://prefix.dev/blog/uv_in_pixi

3: https://pixi.sh/latest/features/lockfile/#why-a-lock-file

Tangent: to run things with pixi, you need to either 1) `pixi run thing` 2) `pixi shell` to spawn a new shell with adjusted env or 3) `eval "$(pixi shell-hook -s bash)"` (or similar for other supported shells) to modify your current session.

I found that direnv [1] really improved the ergonomics for me. There's some misunderstanding that direnv requires Nix but that's not true. It does one thing and does it well: load .envrc files when you cd that path.

I have a lil `.envrc` that looks like this:

    # Load pixi shell settings.
    eval "$(pixi shell-hook -s bash)"

After that, you can just run `python` and it will run whatever python you asked it to install (`pixi add python` adds the latest python 3 in conda by default).

--

1: https://direnv.net/

I like Python, but those version suffixes are a very common problem. But in 2024 python should be python 3 and pip should be python3-pip.

This situation is also partially why there is so much python tooling around versions, environments and dependencies.

I would love to have a little less dynamic Python, that could be compiled to not huge binaries.

I think people assume an alias exists. Same with `python` being an alias for `python3`. Some linux distros default to creating that alias when you install python3.
I use pyenv, seems to work very well.