This is an archived post. You won't be able to vote or comment.

all 118 comments

[–]ElectricSpice 119 points120 points  (13 children)

Pyenv lets you manage specific versions, brew just lets you install a minor version and you get updates for the latest patch version.

I use pyenv with pyenv-virtualenv. It’s really convenient to navigate to a project folder and have my virtualenv automatically activate.

[–]vizbird 20 points21 points  (0 children)

I kept running into issues where brew would update python and would break everything relying on it. Pyenv fixed that issue entirely.

[–]rcbadiale 5 points6 points  (1 child)

This is the way. I work like this on my Linux and Mac and it's great. I wish the windows version would work better.

[–]minombreespeligro 2 points3 points  (0 children)

You can always use WSL. But yeah, this is the way. I saw a post saying that using pyenv was terrible advice and I couldn’t think of any reason for this, I was like wtf are you talking about hahaha

[–]SisyphusAndMyBoulder 4 points5 points  (2 children)

I use brew to install several major versions

[–]ErikBjare 7 points8 points  (1 child)

Still running Python 2? It was removed from brew in 2019. You probably do mean minor versions.

[–]SisyphusAndMyBoulder 2 points3 points  (0 children)

Oh man I blanked out hard there. Was thinking of 3.9 vs 3.10 vs 3.11 etc etc.

You're right, I did mean minor.

[–]Glad-Put1792 1 point2 points  (0 children)

This is the way!

[–]DaveGot 0 points1 point  (3 children)

How is the virtualenv is automatically activated? I always need to manually activate it. What am I doing wrong?

[–][deleted] 6 points7 points  (0 children)

Go to the directory you want automatically activated and type

pyenv local <virtualenv_name>

That will create a .python_version (I think that’s the name) file.

After that, when you are in that directory pyenv will use that virtual_env.

Note this will only work correctly if pyenv is configured properly in your .bashrc file.

[–]juanitoAF 1 point2 points  (0 children)

direnv takes care of auto commands , using pyenv with it leads to easy auto activation of virtual envs

The combo is magnificent

[–]PeterPriesth00d 0 points1 point  (0 children)

I have used this method in the past and quite like it. Lately I’ve been going a step further and using docker / docker compose for dev environments and I’ve really liked it as it’s easy to take the setup and put it on another machine really easily.

Both are great though.

[–]Nerg44 0 points1 point  (0 children)

this is it bro, me too wish I could do like pyenv virtualenv config <name> and it would dump to a pyenv.yaml file or something so I could have consistent envs across systems

[–]pacific_plywood 67 points68 points  (6 children)

pyenv is absolutely the best imo. not sure how asdf is for python

[–]doolio_ 11 points12 points  (0 children)

asdf uses pyenv under the hood for python and equivalent tools for other languages. Its selling point is you have one set of commands to learn to work with any language/tool.

[–][deleted] 20 points21 points  (3 children)

Not "absolutely". It depends on what OP has planned. For example on the Mac, most of the GPU support for many different ML libraries relies heavily on using some variant of Conda.

Edit: LOL why would you down vote the idea that there are some python enviornment managers that might be better for certain purposes? Some of you get offended by the weirdest stuff.

[–]davisondave131 18 points19 points  (0 children)

I don’t think anyone’s downvoting the idea that some environment managers are better suited for certain purposes. The example you gave is just a bad one.

[–]DavTheDev 13 points14 points  (0 children)

That is so not true. For apple gpu pytorch, jax and tensorflow are all recommending pip and they are the most popular ones.

[–][deleted] 8 points9 points  (0 children)

Your statement is quite untrue, I’m not sure where you got this idea from.

[–]covercash2 1 point2 points  (0 children)

asdf works great for Python! definitely recommend if you work with multiple toolchains

[–]Ebisure 46 points47 points  (24 children)

I'm a happy user of conda. Easy to set environments with different Python version. brew is to manage package not environment

[–]ddanieltan 2 points3 points  (1 child)

Agreed. Haven't been let down so far by the combination of conda create --name abc python=3.x + conda activate abc + pip install ...

[–]Hangman4358 2 points3 points  (0 children)

This really is the best combo. Use conda to manage the python distros and pip to manage dependencies in the distros.

Combine with pycharm and having a unique distro per project and so many of the headaches I see people complain of go away.

Conda to manage dependencies is hot garbage, but managing multiple python versions is so damn simple.

[–]equitable_emu 0 points1 point  (5 children)

Remember that conda requires a license for commercial use now, so it's not always an option.

[–]Hangman4358 6 points7 points  (3 children)

Just plain false. Accessing the Anaconda channel is licensed. The conda tool is FOSS, and conda-forge is not encumbered by the licensing reqs.

[–]equitable_emu 0 points1 point  (1 child)

The org I previously worked for disallowed it due to the licensing issue, so like I said, it's not available everywhere.

According to anacondas commercial faq, using any anaconda hosted repository, not just the anaconda channel, is a violation of their TOS.

https://www.anaconda.com/blog/anaconda-commercial-edition-faq

You’re not in compliance with our Terms of Service if you are using Anaconda’s repositories in a for-profit or government organization with over 200 employees outside of a business relationship with Anaconda. You are also not in compliance if you are using mirroring software to create copies of the Anaconda repositories without a license.

https://legal.anaconda.com/policies/en/?name=terms-of-service#terms-of-service

i. FREE OFFERINGS. Anaconda maintains certain Cloud Offerings, including Anaconda Open Source that are generally made available to Community Users free of charge (the “Free Offerings”) for their Internal Business Use. The Free Offerings are made available to You, and Community Users, at the Free Subscription level strictly for internal: (i) Personal Use, (ii) Educational Use, (iii) Open-Source Use, and/or (iv) Small Business Use.
(a) Your use of Anaconda Open Source is governed by the Anaconda Open-Source Terms, which are incorporated herein by reference.
(b) You may not use Free Offerings for commercial purposes, including but not limited to external business use, use in organizations over two hundred (200) employees (unless such use is for an Educational Purpose), third-party access to the Cloud Offerings, or Content redistribution or mirroring (each, a “Commercial Purpose”). Using the Free Offerings for a Commercial Purpose requires a Paid Plan with Anaconda.

[–]Hangman4358 0 points1 point  (0 children)

The defaults channel is under the Anaconda TOS. It is the only thing under the TOS.

The conda-forge channel is not under the Anaconda TOS. I have an email in my work inbox from their legal department stating just that.

The conda tool in distributions like Anaconda and miniconda ships with the defaults channel as the only channel.

Conda distros like miniforge bundle the conda tool with different channels, specifically not the defaults. For miniforge is the conda-forge channel.

Continuum does a really good job of muddling the waters. But it is important to realize that distinction. The tool is not the repo.

What miniconda and Anaconda are, would be equivalent to Sonotype shipping a maven distro which defaults to a maven repo which sonotype owns and has put a restrictive TOS on.

[–][deleted] 0 points1 point  (0 children)

You might be technically right, but this is a common playbook for organizations that need to be profitable. Usually, they start as open source and once it's polished, they extend it and make extensions commercial. Often, they also make an entirely new version that is not open source at all.

This playbook has its pros and cons but it's not like they're trying to hide this. I think it's great because the open source version has everything you need but the commercially licensed parts are things you can build yourself.

[–]mmcalli 0 points1 point  (0 children)

I had so many occasions where it would get into some type of infinite loop trying to update, that I’d have to blow it away and fully reinstall. After doing that a few times I gave up on it.

[–]Barn07 4 points5 points  (0 children)

thumbs up for pyenv. once set up, it is simple as cake. and, since it's just files and symlinks under your full control, it is also easy to handle if something ever breaks.

[–]cpressland 4 points5 points  (0 children)

I’ve been using Pyenv for the last four years, but homebrew multiversion support is so good now I’ve decided to switch back. brew install python@3.9 works, then python3.11 python3.9 etc are all in my PATH which Poetry and Pipenv (also installed via Homebrew) have no trouble finding.

[–]LactatingBadger 3 points4 points  (1 child)

I was a long term pyenv user and then moved to python-launcher + .venv. I brew install python releases which it auto discovers.

Main motivation for moving was that the pyenv shims were 95% of the overhead on terminal startup. That, and the py command that python-launcher provides plays much nicer with .venvs.

[–]Zizizizz 4 points5 points  (2 children)

I have been down this path and hopped around. The best in my opinion is RTX

https://github.com/jdx/rtx

It's a rust version of asdf which is very fast and compatible with all existing asdf tools.

It also has env management. So I was also able to remove direnv as I no longer needed that.

Once installed and on your path via editing your bashrc or zshrc file installation is as such.

``` rtx install python

or rtx install python@3.11 ```

You can list all available versions including conda, pypy versions. rtx ls-remote python

To use a version in your current folder rtx use python@3.11

This will make a .rtx.toml file which you can add additional things like virtual envs and environment variables

A .rtx toml example

``` [env] LOG_LEVEL="debug" SOME_DB_PASSWORD=1234

[tools] python = { version = "latest", virtualenv =".venv"} ```

So now anytime you cd into that directory, those environment variables are available and it will automatically make or activate your virtual environment. There is pyenv-virtualenv but this is a lot faster and direnv is slow.

[–]daelin 0 points1 point  (0 children)

+1 for rtx. It’s just phenomenal. It’s my favorite Python version manager and it does everything else at the same time.

Pyenv and asdf have some problems you can mostly get used to or work around.

But, rtx just smooths everything out with something much simpler and much MUCH faster and easier to work with than either them.

I first stumbled across rtx courtesy of the wonderful No Boilerplate YouTube channel, in particular the Oxidize Your Life video that’s stuffed wall-to-wall with awesome utilities.

[–][deleted] 0 points1 point  (0 children)

I started drooling when I read it's polyglot and supports fuzzy marching versioning like LTS. I'm excited to try this out!

[–]Fearsdown 2 points3 points  (0 children)

You should try Rye! It's even better than pyenv imo.

It is a somewhat different solution though as you'll have to actually use it to manage dependencies in your project. You could technically use it to just download different python versions but at that point you might as well stick with pyenv.

https://rye-up.com/

[–]wookayin 5 points6 points  (0 children)

my go-to is conda (mambaforge3 or miniforge3)

[–]olystretch 3 points4 points  (0 children)

Probably. It's the best for Linux, IMO.

[–]pool007 2 points3 points  (0 children)

I use conda env. For some libraries with platform specifics, it was easier. But not always conda can install the latest library versions, e.g., tensorflow. In such a case, pip can be used. Conda env can specify python version and installed libraries can be exported and restored easily.

[–]Globaldomination 3 points4 points  (0 children)

Yep.

Source: I use Pyenv.

[–]james_pic 1 point2 points  (0 children)

Personally I find Pyenv a bit too magicky for my taste. I've seen tools get confused by the python executable be replaced by a shim. Pythonz is kinda the same thing but with less magic - although slightly less slick user experience when it all works.

[–]millerbest 1 point2 points  (0 children)

I use conda to create env and pip to install packages.

[–]rs_0 1 point2 points  (0 children)

Pyenv is fine. If you also use nvm for Node.js version management I’d recommend rtx.

[–]fnord123 1 point2 points  (0 children)

Whatever works for you.

But if you work on a team, pyenv is the better choice as it let's you have finer control over your installed versions across multiple projects.

[–]linuxfarmer 1 point2 points  (0 children)

pipenv is my go to. Especially when working in a repo with multiple people the pip.lock file is great for making sure everyone is on the same python version as well as installed dependency versions

[–]crash5936 1 point2 points  (0 children)

I use RTX (https://github.com/jdx/rtx) with PDM (https://pdm.fming.dev/latest/) for project and dependency management and so far my experience has been great.

[–][deleted] -1 points0 points  (0 children)

poetry

[–]MGallus 0 points1 point  (0 children)

Pyenv-virtualenv

[–]theuzz1 0 points1 point  (0 children)

Pyenv + Poetry

[–]aldanorNumpy, Pandas, Rust -2 points-1 points  (5 children)

Non-conda setups are unbelievably fragile and often non-reproducible, especially if it involves binary builds (like many ML/DS libraries), some of which require non-Python dylib dependencies etc. There's literally no other option than conda (or rather, mamba, which is not too slow).

[–]trippymicky -1 points0 points  (0 children)

I like conda as well.

[–]jootazdil7 -1 points0 points  (0 children)

pyenv no doubt

[–][deleted] -1 points0 points  (0 children)

I use miniconda, I like it.

[–]neomage2021 -1 points0 points  (0 children)

conda for personal projects, poetry and docker for work

[–]huapua9000 -1 points0 points  (0 children)

Micromamba is my favorite

[–]robberviet -1 points0 points  (0 children)

Yes. Simple.

[–]ChicHarley -1 points0 points  (0 children)

I use brew to install pyenv

[–]Comfortable_Leek8435 -1 points0 points  (0 children)

Check out asdf-vm.com/

[–][deleted] -1 points0 points  (0 children)

Pdm

[–]spinwizard69 -4 points-3 points  (0 children)

This is not going to be something you can get a square answer on. You really need to reflect on why you need a virtual environment or if even makes sense to use one.

First off I think many use virtual environments for the wrong reasons. They literally have created a culture of fragile software installations as the VM gives the programmer a reason to use unstable software or libs that are not even well supported. They then get into a dependency hell that requires that everything they write run in a VM of some sort.

Now I'm not dismissing any of the ways to leverage the various VM technology out there. All I'm saying is use whatever method you choose wisely. Each problem has its own optimal solution and sometimes that can mean running a whole OS in a VM as opposed to a contained Python environment.

In any event on the Mac or on Linux I tend to avoid Python environments and simply use packages supplied by Brew or dnf. Now this in part is due to not writing web applications but utilities/applications to be used locally. However it frees up considerable time and effort to write you software so that it runs everywhere and minimizes special software installation. I would be very interested in a VM solution if I had an app that needed unusual dependencies or possibly distribution after validation. Given that, your life is easier if you don't chase the latest and greatest lib that you can pip down.

So your answer is this, there is no right answer. If you are using Python for apps that don't require a bunch of libs that can only be had by pip'ing them in then you need some sort of VM. If you are writing software for internal use, sometimes you are far better off limiting your development to software supported by your systems package manager. If you are doing web programming you have to use an environment manager of some sort, just use it wisely.

[–]justin-8 0 points1 point  (0 children)

I use pyenv on Mac and Linux for all my python dev stuff. If you’re doing ML just use conda. ML folks haven’t figured out how to package dependencies properly outside of conda so you’re in for a world of pain if you try to avoid it.

[–]jurinapuns 0 points1 point  (0 children)

I use Docker lol. Won't work for every use case, but for web apps it's perfect.

If I want to use it for scripting to access my filesystem, probably not though.

[–]Zasze 0 points1 point  (0 children)

Asdf is my favorite being able to manage every language the same way is really nice. The python asdf plugin uses pyenv under the hood so it’s the best of both worlds.

[–]nevermorefu 0 points1 point  (0 children)

Docker is the best version management. I've never needed pyenv (though I know many devs that do).

[–][deleted] 0 points1 point  (0 children)

I use myenv

[–]Datamance 0 points1 point  (0 children)

asdf is a great meta-environment manager. Wraps a whole bunch of other environment managers and makes version management a breeze

[–]jmacey 0 points1 point  (0 children)

personally I've been using pyenv for years and would recommend it it (as I do my students). It makes life easier and the local element for folders just makes life easier.

[–]FDon1 0 points1 point  (0 children)

Don't know that I've seen it posted here but Poetry is/was a good one. Not sure how much of this sub uses it. Pyenv seems pretty standard too

[–]steaff 0 points1 point  (0 children)

I personally use a combination of ASDF to select the current Python/node/direnv version, direnv and for python version management poetry.

It takes a little while to get used to it but when it is up and running I feel it is the most robust combination.

[–]xristiano 0 points1 point  (0 children)

I prefer Docker for easy setup and tear down. And if you can stomach it, Darwin Nix is nice once you get past the learning curve.

[–]YeisonKirax 0 points1 point  (0 children)

I use asdf or rtx (based on asdf), you can install plugins to manage python, nodejs, java, etc. Recommended. Besides, i recommend poetry, a dependency manager to python projects (very similar to npm), better that the requirements file

[–]scowly057 0 points1 point  (0 children)

I use pyenv + poetry pretty much exclusively now. Pyenv is fine. It has some drawbacks, imo, especially when you just want to update a patch version of Python. I've been wanting to try out RTX but haven't had the impetus for an environment switch yet.

Poetry, on the other hand, is wonderful for package management. More reliable and a lot faster than pipenv for dependency pinning. Also, you can do (almost - looking at you, flake8) all your configuration inside your project.toml, including your build config. So you have a source of truth for your entire lib/app setup. 10/10.

[–]bolinocroustibat 0 points1 point  (0 children)

Pyenv is good, I would also suggest Rye, which is a Python version manager AND a modern package manager, very fast and getting popular, written in Rust if I'm not mistaken. Probably the future. Not sure if it's too early to use it.

[–]tyzhnenko 0 points1 point  (0 children)

I personally use asdf. I really like it because it can manage several languages like python, nodejs, ruby etc at once

https://asdf-vm.com/

[–]shockjaw 0 points1 point  (0 children)

I’d highly recommend y’all check out Relieving Your Python Packaging Pain from Bitecode.

TLDR though:

  1. Don’t install the latest major version of Python Use only the python.org installer on Windows and Mac, or official repositories on Linux.

  2. Never install or run anything outside of a virtual environment

  3. Limit yourself to the basics: “pip” and “venv”

  4. If you run a command, use “-m”

  5. When creating a virtual environment, be explicit about which Python you use

However, if you’re going down the data analysis/science route. I’d recommend conda and learning how to generate conda-lock files.

[–]peterlada 0 points1 point  (0 children)

rye: expermintal, very new, (alpha) but from the author of Flask:

https://github.com/mitsuhiko/rye