Search code examples
pythonvirtualenvpyenvpython-venv

What do I need for managing Python versions and libralies?


I'm new to Python, and going to use Python in the next job.

I'm now using pyenv to version Python and its libraries, but some of blog posts says we don't necessarily need pyenv for versioning.

Some say we need pyenv and virtualenv, others say we need only venv, and or need nothing...

It's a little complicated.

I think if I don't use versioning tools like pyenv, I'm in trouble in using tools that need Python2, such as npm.

  • I use only Python3
  • I will develop in many projects, both Web developing and data analysis with Python
  • I use MacOS

Under these conditions, what is the best stack to manage my Python environment?


Solution

  • pyenv manages different Python versions. It's useful if you develop multiple projects that use different Python versions. If you are going to stick to only Python 3, you don't have to use pyenv.

    Different virtual environment wrappers (virtualenv, virtualenvwrapper) help you isolate Python environments for different projects. E.g. if you are going to use requests library, virtual environment will enable you to use different versions of requests library in different projects (e.g. at some point you can update to new requests version on Project A, but decide to keep old version on Project B). Even if you are going to work on a single projects, it's still recommended that you use virtual environment.

    I personally prefer virtualenvwrapper to virtualenv. It makes it really simple to create environments, add some custom post activation logic to environments (e.g. set env variables, or change working directory), and switch between active environments.