uv is a very popular way these days to work with current Python without affecting your global version.
Under highlights it lists:
"A single tool to replace pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv, and more."
https://x.com/kolibril13/status/1885269093445460015 Janaury 2025
"With yesterday's release of uv, it's now possible to start any python version with uvx. For example:
uvx [email protected] or uvx [email protected] "
https://bsky.app/profile/simonwillison.net/post/3lhf5upktgs2m January 2025
"Tiny TIL: I just figured out how to run pytest with a different Python version against my pyproject.toml/setup.py projects using 'uv run'
uv run --python 3.12 --with '.[test]' pytest
https://til.simonwillison.net/pytest/pytest-uv "
Plus, see the 'The Modern Approach: pyproject.toml with uv' section of Why Use uv Projects Instead of requirements.txt?.
Oh wait, despite your post's title, I see "But I would prefer to work in a Jupyter notebook." You'll want to see this post from kolibril13 (Jan-Hendrik Müller).
Also see this discussion (Sorry, it is not easy to format that is here. Please check out the links.):
https://x.com/rahuldave/status/1845847321176678893
https://x.com/kolibril13/status/1845771352747221430 October 2024
"It was always difficult to install @ProjectJupyter locally. I think uv simplifies this process a lot!
1️⃣ install uv with https://docs.astral.sh/uv/getting-started/installation/
2️⃣ install + start jupyter with uvx jupyter lab
The whole process took about 30 seconds.
More about uv+jupyter in this 🧵 1/7"
"Best of all, the command for both the initial installation-and-first-run, as well as all future runs, is always the same: uvx jupyter lab.
This is thanks to some smart caching magic happening under the hood with uv."
"It's also possible to use other python versions.
"uvx --python 3.13 jupyter lab" will start with the latest python, and it will even manage the python installation for you."
"here's the same with "uvx --python 3.10 jupyter lab". It should be noted that I did not have any python 3.10 installation before on my system, and all the screen recordings are in real time, not edited."
"convenient way to install packages within the notebook: !uv pip install matplotlib"
"packages can also be added by the --with flag.
uvx --python 3.12 --with anywidget jupyter lab.
This is in particular useful for packages like #anywidget by
@trevmanz, as some packages (e.g. anywidget) cannot be installed in an already running notebook kernel."
"Finally, it’s worth mentioning that the above examples are great for prototyping ideas or running one-off scripts that don't live within a project. And that’s it! Thanks for reading, and feel free to share your experiences with uv in the comments ✨ 7/7"
https://x.com/rahuldave/status/1845847321176678893
>"How does uv know to install jupyterlab? I am having my students do pixi init folder; cd folder; pixi add python numpy matplotlib scipy scikit-learn pandas jupyterlab; pixi run jupyter lab these days but you seem to be suggesting that the incantations can be smaller with uv?"
https://x.com/kolibril13/status/1845850589944528963.
>'> How does uv know to install jupyterlab?
uvx is alisas for uv tool run
https://docs.astral.sh/uv/reference/cli/#uv-tool-run
and tools are Python packages that provide command-line interfaces. https://docs.astral.sh/uv/concepts/tools/
So uvx jupyter lab is the same as uv tool run jupyter lab
Furthermore from their docs:
"Tools can be invoked without installation using uv tool run, in which case their dependencies are installed in a temporary virtual environment isolated from the current project." [...] "When running a tool with uvx, a virtual environment is stored in the uv cache directory and is treated as disposable, i.e., if you run uv cache clean the environment will be deleted."
> but you seem to be suggesting that the incantations can be smaller with uv?
yep, I think the uv interactions can be smaller than with pixi, as you don't have to activate environments.'
conda,pyenv,asdf.noexec, preventing any files stored there from being invoked as executables.