Managing Python Environments with direnv and pyenv

python_tutorials

Introduction

As Python developers, most of us are familiar with Virtual Environments. One of the first things we do when working on a new project is to create an environment. We commonly use virtualenv or venv exactly for that purpose.

Each project we work on uses different packages and may even be compatible with only one Python version.

Doing something repeatedly warrants automation. In this article, we’ll see how direnv and pyenv can help us do that.

As a side note, some modern IDEs already automated these steps. For example, PyCharm will create the Virtual environment when initializing a project:

PyCharm's automated python environment management

Although automating all these steps is a great win if we use IDEs that support such functionalities, a more generic solution should be IDE-agnostic.

The Problems of virtualenv

Imagine we found a project on GitHub and we would like to play around with it. Pyweather is a simple script that requests the extended weather forecast for our location and prints it on the terminal.

These are the steps we take in order to try the

To finish reading, please visit source site