Skip to content

Instantly share code, notes, and snippets.

@YoraiLevi
Created October 27, 2024 04:48
Show Gist options
  • Save YoraiLevi/b1ef408b50fd60ac1cbf90621b60b0bd to your computer and use it in GitHub Desktop.
Save YoraiLevi/b1ef408b50fd60ac1cbf90621b60b0bd to your computer and use it in GitHub Desktop.
Check if the notebook is executed in vscode colab or pyodide based platform
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'in_vscode=True, in_colab=False, in_pyodide=False'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import os\n",
"import sys\n",
"in_vscode = \"VSCODE_CWD\" in os.environ or \"VSCODE_PID\" in os.environ # running in vscode\n",
"in_colab = \"google.colab\" in sys.modules # running in colab\n",
"in_pyodide = '_pyodide' in sys.modules\n",
"f\"{in_vscode=}, {in_colab=}, {in_pyodide=}\""
]
}
],
"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.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment