Python versions and virtual environments
If you're working in the field of machine learning, it's only a matter of time before you run into Python dependency hell. Enter version managers and virtual environments.
As I set up my dev environment for my master's research, I want to get in front of Python package dependency conflict nightmares. I have pretty basic requirements at the moment: I want to be able to easily switch Python versions and create virtual environments. That's it.
I've been digging through a number of posts on the topic and it looks like, for my needs, pyenv with the pyenv-virtualenv plugin is the way to go. It's a straightforward solution and does what I need it to do.
I am also considering manually installing Python versions, manually switching between them, and then using the built-in venv module to create the virtual environments. However, this is guaranteed to lead to headaches; I know with this process I'm bound to break something at some point - did you notice how I used the word manually twice in the first sentence of this paragraph?
Another option is to use pyenv
to manage the Python versions and then use venv
to manage the virtual environments. There is really no need to use two tools though, it's unnecessary complication. The pyenv-virtualenv
plugin will make life easier and will ultimately use venv
under the hood (as I don't have virtualenv
or conda
installed).
Of course, there are many other tools out there and, I'll admit, I was getting a bit confused between all the options. Here's my understanding of some of the tools I read about:
pyenv
is a simple Python version manager that does not rely on Python itself.pyenv-virtualenv
is a plugin forpyenv
used to create virtual environments. It usesvenv
,virtualenv
, orconda
under the hood to create the virtual environments depending on your setup.pyenv-virtualenvwrapper
is a plugin forpyenv
used to create virtual environments withvirtualenvwrapper
.venv
is a module in the standard library (as of Python 3.3) used to create virtual environments.virtualenv
is a Python library used to create virtual environments. It offers more features thanvenv
.virtualenvwrapper
is a set of extensions forvirtualenv
.pyvenv
is deprecated (in favour ofvenv
). Don't worry about it.conda
is a command line tool for package and environment management. It's popular in the Python community but is language agnostic.miniconda
is a distribution that includesconda
, Python, and some useful Python packages. It's a lightweight version ofanaconda
.anaconda
is a distribution that includesconda
, Python, and a heck of a lot more Python packages (mostly data science related) thanminiconda
.poetry
is a tool for dependency management and packaging in Python. It automatically creates and manages virtual environments.asdf
is a version manager that can be used for a wide range of languages.
Your situation might be different than mine, and you might go a different direction. Though if all you need is a simple, no-fuss setup, it seems pyenv
is the answer.
Discussion