1

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?

Taichi
  • 2,297
  • 6
  • 25
  • 47

1 Answers1

1

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.

ozren1983
  • 1,891
  • 1
  • 16
  • 34
  • What about pipenv? – NobbyNobbs Aug 18 '18 at 15:00
  • 2
    pipenv will probably become a standard in near future and replace virtualenv and virtualenvwrapper. It's based on the new Pipfile that will replace requirements.txt. However, it's still under active design and development and too new for me to use in production. – ozren1983 Aug 18 '18 at 15:10
  • Thank you! I wonder if `venv` is better than `virtualenv`, cuz venv is python3's default tool? Or is virtualenv better? – Taichi Aug 18 '18 at 15:16
  • I think I use `pyenv` in case I need Python2, and `virtualenv` or `venv` to create environments too. – Taichi Aug 18 '18 at 15:17
  • 1
    Yes, there is also venv in Python 3, but I don't think many people actually use it. If you're going to use Python 2 and Python 3, then you need pyenv, otherwise just virtualenv/virtualenvwrapper/venv will do. Here is a great overview of all these options: https://stackoverflow.com/questions/41573587/what-is-the-difference-between-venv-pyvenv-pyenv-virtualenv-virtualenvwrappe – ozren1983 Aug 18 '18 at 15:25