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:
pyenvto install other python versions, along with
pyenv-virtualenvto better support
venv, generally managed by higher-level tools like Poetry, Pipenv or Hatch.
Dotenvto 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
.envto 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:
oh-my-zshto always source
.env. This breaks the virtual environment the first time, so you need to
cdback to the directory. Or,
- Don’t use the