How to select python interpreter for .ipynb file while using uv for python environment creation?

For test.ipynb file i am trying to select the python environment for kernel. However my environment created from uv is not being displayed as an option and upon trying to manually paste the path is also not working. How do we make .ipynb files work within uv?
Check the image where .venv is not being shown as an option: Read more
Answer
One obvious solution would be:
- create a uv Project folder and enter it - choose the python version
uv init mytest --python 3.12
cd mytest
# move your test.ipynb into it
mv /path/to/test.ipynb ./
- install Jupyter notebook into the project
uv add jupyter
- run jupyter of this project
uv run jupyter notebook
Now you can open your test.ipynb and from inside the Jupyter Notebook you can do
!uv add your-packages
and control uv
from inside your Jupyter Notebook.
Add further dependencies or delete them.
And update uv
accordingly.
Test inside the Jupyter notebook with:
!which python
and
!python --version
You will see it is the environment (.venv/bin/python
) of your project.
uv
's advantage
The great thing of uv
is - even if you create thousands of environments - if you use the same Package version,
for all those environments, the Packages are installed physically only exact once. And all the environments will use hard- or softlinks to have them virtually inside their environment. So this is really hard-drive-memory efficient!
While if your coworker gets your pyproject.toml
file, he can recreate in his machine exactly your environment with Jupyter Notebook.
This is quite amazing.
Enjoyed this article?
Check out more content on our blog or follow us on social media.
Browse more articles