Create your folder, and initialize the virtual environment with
pyenv virtualenv. I will use Python version
3.9.5 and call my environment
pyenv virtualenv 3.9.5 project-venv
Activate your virtual environment with
pyenv activate project-venv
Confirm that this is working by checking your Python version with
python -V, and you should see
You can also create a file
.python-version at the root of your project with the path to the virtualenv:
This file tells
pyenv which Python version should be used. It will also allow
pyenv to automatically activate the
project-venv when you open the project folder in Terminal.
If this does not work, ensure that your
.bashrc has the line
eval "$(pyenv virtualenv-init -)".
In VSCode's settings, set
python.pythonPath to the path of the virtualenv
project-venv we created in the previous step. In my case, it's
~/.pyenv/versions/3.9.5/envs/fit-venv/bin/python (On Mac). To confirm that this is working, see the bottom left of your VSCode, where you should see something similar to
Python 3.9.5 64-bit ('venv': venv).
ipykernel before running code:
pip install ipykernel
Once installed, create a block:
and run it with
To list out all versions and virtualenvs with pyenv, run
pyenv versions. At the bottom, we should see the virtualenv we created:
... system ... 3.9.5/envs/project-venv project-venv
pyenv uninstall project-venv and
pyenv virtualenv-delete project-venv. If this does not work, open
~/.pyenv/versions/3.9.5/envs, and manually delete the virtual environment folder.