pyenv
brew update
brew install pyenv
brew install pyenv-virtualenv
Add pyenv to your shell startup file:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init --path)"' >> ~/.zshrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
source ~/.zshrc
check installed correctly:
pyenv --version
List available Python versions:
pyenv install --list
# specific version
pyenv install 3.9.10
Set a global Python version:
pyenv global 3.11.4
Set a local Python version in a project directory:
cd my_project
pyenv local 3.9.10
Create a Virtual Environment for Jupyter
pyenv virtualenv 3.9.10 jupyter-env
List available virtual environments:
pyenv virtualenvs
Activate the Environment
pyenv activate jupyter-env
Check if the correct Python version is active:
python --version
Install Jupyter Notebook
pip install jupyter
jupyter --version
Add Virtual Environment to Jupyter as a Kernel
pip install ipykernel
python -m ipykernel install --user --name=jupyter-env --display-name "Python (jupyter-env)"
jupyter kernelspec list
Task | Command |
---|---|
Install pyenv | brew install pyenv pyenv-virtualenv |
Install Python 3.9.10 | pyenv install 3.9.10 |
Create a virtual environment | pyenv virtualenv 3.9.10 jupyter-env |
Activate the virtual environment | pyenv activate jupyter-env |
Install Jupyter Notebook | pip install jupyter |
Add virtual environment to Jupyter | python -m ipykernel install --user --name=jupyter-env --display-name "Python (jupyter-env)" |
Start Jupyter Notebook | jupyter notebook |
List available Jupyter kernels | jupyter kernelspec list |
Deactivate the virtual environment | pyenv deactivate |
Delete the virtual environment | pyenv virtualenv-delete jupyter-env |