Pyenv and Jupyter Notebook Integration
Last updated:Table of Contents
Examples run on MacOS
Add pyenv Environment as Kernel
Running ipython kernel install alone doesn't seem to work for PyEnv.
Do this instead:
1) Activate the environment: $ pyenv activate my-venv
2) Install the kernel with $ ipython kernel install --name "my-venv" --user
(This creates a file in ~/Library/Jupyter/kernels/my-env/kernel.json
)
3) The created file (on the path above) will probably have the wrong path to the Python executable.1 Open it and edit it to point to the PyEnv executable:
{
"argv": [
"~/.pyenv/versions/my-venv/bin/python", # <-- HERE
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "my-venv",
"language": "python",
"metadata": {
"debugger": true
}
}
Troubleshooting: No module named ipykernel_launcher
You need to install ipykernel
in the virtualenv you want to use.
References
1: In my case it pointed to a native Python version: /usr/local/opt/python@3.11/bin/python3.11