-
-
Save fepegar/235c65fff85c0cd62f226d2711ac48b0 to your computer and use it in GitHub Desktop.
Create a temporary Python environment with uv and open a Jupyter notebook with VS Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PYTHON_VERSION="3.13" | |
tmp_dir=$(mktemp -d) | |
uv init \ | |
--bare \ | |
--quiet \ | |
--python $PYTHON_VERSION \ | |
$tmp_dir | |
cmd=(uv add --directory $tmp_dir ipykernel ipywidgets rich) | |
for dependency in "$@"; do | |
cmd+=( "$dependency") | |
done | |
"${cmd[@]}" | |
notebook_contents=$(cat <<EOF | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%load_ext rich" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": ".venv", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.13.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} | |
EOF | |
) | |
echo $notebook_contents > $tmp_dir/notebook.ipynb | |
code --new-window $tmp_dir | |
code --reuse-window $tmp_dir/notebook.ipynb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment