Skip to content
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

alternative to ! pip install ... to update env #1290

Open
Borda opened this issue Apr 18, 2024 · 3 comments
Open

alternative to ! pip install ... to update env #1290

Borda opened this issue Apr 18, 2024 · 3 comments

Comments

@Borda
Copy link
Contributor

Borda commented Apr 18, 2024

I am just building a gallery for TM, and some examples will have additional dependencies, so I was thinking about using the Jupyter approach and adding ! pip install ... to install required packages instead of having an extra file with all requirements for the whole gallery. Advenatge of ! pip install would be reproducibility as a user would download a particular sample and still would be executable

Here is what I tried:

# %%
# Installing dependencies
#
#     .. code-block:: bash
#
#       %%bash
#       pip install -q "scikit-image"

# %%

from skimage.transform import rescale

also

# %%
# Installing dependencies
#
#     .. code-block:: bash
#
#       ! pip install -q "scikit-image"

# %%

from skimage.transform import rescale

failed with

Warning, treated as error:
../../examples/image/plot_spatial_correlation_coef.py unexpectedly failed to execute correctly:
    Traceback (most recent call last):
      File "/home/docs/checkouts/readthedocs.org/user_builds/torchmetrics/checkouts/2508/examples/image/plot_spatial_correlation_coef.py", line 29, in <module>
        from skimage.data import shepp_logan_phantom
    ModuleNotFoundError: No module named 'skimage'
make: *** [Makefile:[19](https://beta.readthedocs.org/projects/torchmetrics/builds/24114586/#227377974--19): html] Error 2

inspired from https://sphinx-gallery.github.io/stable/configuration.html#making-cell-magic-executable-in-notebooks

@lucyleeow
Copy link
Contributor

If I understood correctly, you want to pip install when building the docs?

promote_jupyter_magic adds code blocks to Jupyter notebooks. Code block starting with jupyter cell magic, inside of a 'text' block will be promoted to a code block when making Jupyter notebook.

When only execute python via AST when building the gallery. I am not sure we want to add bash commands in...

@Borda
Copy link
Contributor Author

Borda commented Apr 20, 2024

If I understood correctly, you want to pip install when building the docs?

Correct

promote_jupyter_magic adds code blocks to Jupyter notebooks. Code block starting with jupyter cell magic, inside of a 'text' block will be promoted to a code block when making Jupyter notebook.

I did but seems it didn't work, https://github.com/Lightning-AI/torchmetrics/pull/2508/files#r1573175086

@lucyleeow
Copy link
Contributor

You will still need the dependency when building the docs.

The pip install code block is only added to the jupyter notebook that is generated. Does the jupyter notebook have the added code block?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants