-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add hidden cell to install colab missing deps #152
Conversation
703c6c4
to
6cd0818
Compare
5e32bf2
to
f9b97dc
Compare
4849fc0
to
e116165
Compare
The jupyterbook/content/code_gallery/data_analysis_and_visualization_notebooks/2021-10-25-ERDDAP-interpolate.ipynb is failing with a 403 b/c that ERDDAP server doesn't like to be accessed and prohibits folks who try to use it :-/ It is safe to merge but we should consider using a more forgiving server for the interpolation example, one that likes users and let them access data. |
@MathewBiddle this one is ready to go. It kinds of touches almost all the notebooks, adding the GoogleColab dependency check cell, so, to avoid conflicts, it would be nice to get this in before any other PR that edits the notebooks. |
Good to know about that ERDDAP server. It might be worthwhile to see if we can use another one that isn't as restrictive. As far as the changes to the notebooks go, I have a question. If I cloned the repo and tried to run one of the notebooks with this install cell on my local system, would this step install the library on my machine? I'm thinking of the case where I activate the IOOS env (maybe I'm in a different env), would that cell then install those dependencies to my current working env? |
It should not install anything that importlib can find: if importlib.util.find_spec(dep) is None: # this is none only if importlib could not find it in the env
_install(dep)
In that case, yes, b/c the dependency is not there. We can add y/n question to prevent a silent installation without the user response. |
@MathewBiddle I added two safety measures there:
I also fixed a bug where The new cell we are adding is: import subprocess
import sys
COLAB = "google.colab" in sys.modules
def _install(package):
if COLAB:
ans = input(f"Install { package }? [y/n]:")
if ans.lower() in ["y", "yes"]:
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--quiet", package]
)
print(f"{ package } installed!")
def _colab_install_missing_deps(deps):
import importlib
for dep in deps:
if importlib.util.find_spec(dep) is None:
if dep == "iris":
dep = "scitools-iris"
_install(dep) |
I like it! |
For future reference I used this code to find the missing modules on GoogleColab and add the extra cell to the notebooks: