Skip to content

Commit 959533f

Browse files
authored
Merge pull request #499 from zivy/updateGoogleColab
Propagate improved support for google colab.
2 parents bb86266 + 3df818a commit 959533f

23 files changed

+282
-128
lines changed

Python/01_Image_Basics.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
" import google.colab\n",
2929
" import pathlib\n",
3030
"\n",
31-
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
31+
" repo_dir = pathlib.Path(\"/content/SimpleITK-Notebooks\")\n",
3232
" if not repo_dir.exists():\n",
3333
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
34-
" %cd SimpleITK-Notebooks/Python\n",
34+
" %cd /content/SimpleITK-Notebooks/Python\n",
3535
" !pip install -q -r requirements.txt\n",
3636
"\n",
3737
"except ImportError:\n",

Python/02_Pythonic_Image.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
30-
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"/content/SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
34+
" %cd /content/SimpleITK-Notebooks/Python\n",
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/03_Image_Details.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
30-
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"/content/SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
34+
" %cd /content/SimpleITK-Notebooks/Python\n",
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/04_Image_Display.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
30-
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"/content/SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
34+
" %cd /content/SimpleITK-Notebooks/Python\n",
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/05_Results_Visualization.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
30-
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"/content/SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
34+
" %cd /content/SimpleITK-Notebooks/Python\n",
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/10_matplotlibs_imshow.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
30-
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"/content/SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
34+
" %cd /content/SimpleITK-Notebooks/Python\n",
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/11_Progress.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
30-
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"/content/SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
34+
" %cd /content/SimpleITK-Notebooks/Python\n",
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/20_Expand_With_Interpolators.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
30-
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"/content/SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
34+
" %cd /content/SimpleITK-Notebooks/Python\n",
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/21_Transforms_and_Resampling.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
30-
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"/content/SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
34+
" %cd /content/SimpleITK-Notebooks/Python\n",
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/22_Transforms.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
30-
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"/content/SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
34+
" %cd /content/SimpleITK-Notebooks/Python\n",
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

0 commit comments

Comments
 (0)