Pyenv, Pipenv, Dotenv, oh-my-zsh challenges

Filing this one for: I hope I find this post when I have this problem again.

Like many developers, I have a need to juggle multiple python versions: Python 3.8 to run in AWS Lambda; Anaconda for machine learning models; Latest stable version for everyday development.

It seems like these days, the multi-python toolchain looks like this:

  • pyenv to install other python versions, along with pyenv-virtualenv to better support conda.
  • venv, generally managed by higher-level tools like Poetry, Pipenv or Hatch.
  • Dotenv to keep track of environment variables that need to be provided to 12-factor applications.

I am also a fan of oh-my-zsh to automate some basic tasks like:

  • Showing Git branch and commit status in the terminal
  • Activating a project’s virtual environment
  • Adding the variables in .env to the current environment

But when I tried to get this all working on my new Mac, I could not activate any virtual environment. Ultimately I discovered it was because the shell would prompt me to source .env, and that prompt somehow messed up the activation process via the virtual environment. There seem to be two solutions:

  • Tell oh-my-zsh to always source .env. This breaks the virtual environment the first time, so you need to exit and then cd back to the directory. Or,
  • Don’t use the .env plugin.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: