PyEnv
pyenv
is a tool to manage python versions. It has a plugin called
pyenv-virtualenv
which manages virtual environments.
The documentation on the GitHub pages is really nice and succinct:
Shell Setup
I didn't want to use ~/.pyenv
for my installation since it would make it messy
but VSCode is annoying and didn't want to let me select the directory. So, I'm
just going to move it to its default location so that I don't have to fight
with VSCode.
# Pyenv integration
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init - zsh)"
eval "$(pyenv virtualenv-init -)"
I also ran pyenv global system
so that it uses my global install of python
when running globally.
Jupyter Environment Setup
I'm just going to show you commands for my machine-learning
environment:
pyenv install 3.12 # because torch-vision doesn't support 3.13 yet.
# create an environment `machine-learning` with python version 3.12
pyenv virtualenv 3.12 machine-learning
# if ever in this directory or sub-directories, use the machine-learning env
# this is done by setting a file .python-version
pyenv local machine-learning
# verify
pyenv which python
pyenv which pip
python --version
pip --version
Now that the environment is setup, I had a requirements.txt
from my previous
machine learning environment which I just then ran pip -r requirements.txt
Now we want to installed ipykernel
so that we can use the jupyter environment.
Now we can use jupyter environment in VSCode. You can read more details about
this on the VSCode Website.