Managing Multiple Python Versions With Pyenv and Conda
As a CS student, I often find myself working on projects that require different Python versions, each with its own set of dependencies and libraries. In such scenarios, having a reliable and efficient method for managing these versions becomes crucial. Inspired by pyenv 与 conda 双轨制:管理 Python 版本和环境 , this blog post aims to document my experience with managing multiple versions of Python using pyenv and conda.
In this workflow, we use pythons managed by pyenv by default. We'll use conda activate
to use pythons managed by conda when needed.
The installation process provided here is only for macOS (and Z Shell), on other platforms such as Windows you may need to make some changes.
Install pyenv
Use Homebrew to install pyenv
:
1 | brew install pyenv |
Restart your zsh for the changes to take effect.
Use pyenv
1 | pyenv install --list # shows all versions available |
Install conda
Use Homebrew to install anaconda
:
1 | brew install anaconda |
Restart your zsh for the changes to take effect.
Run the following command to disable conda's ability to automatically activate the base environment,if you need:
1 | conda config --set auto_activate_base false |