jupyterlite / demo

JupyterLite demo deployed to GitHub Pages 🚀
https://jupyterlite.github.io/demo
356 stars 192 forks source link

seaborn package is installed, but cannot reference in notebook (gh-pages) #100

Closed spchamp closed 1 year ago

spchamp commented 1 year ago

Description

I've created a fork from the jupyterlite/demo template, spchamp/jupyter-test/

I'm trying to run an illustration with seaborn in JupyterLite. The following is how it appears with my local jupyter-labs installation on openSUSE Tumbleweed.

image

(The reference for the data source is Seeing Through Statistics, 4th ed., by Jessica M. Utts)

This has worked out in my local JupyterLabs installation with each of openSUSE Tumbleweed and FreeBSD. However, it's not working out right now, with my fork of the jupyterlite/demo template at GitHub.

I'm trying to render the following cell with the JupyterLite installation in my gh-pages site:

import seaborn as sns

## data from Utts ch. 9 exercise 9 (table 9.3)

# year = [1982, 1983, 1985, 1986, 1987, 1988, 1989, 1990, 1991]
pop = [231, 234, 239, 241, 243, 246, 248, 249, 252]
rate = [1.32, 1.26, 1.33, 1.49, 1.48, 1.57, 1.65, 1.82, 1.91]

splot = sns.regplot(x=pop, y=rate)
splot.set(title = "Example", xlabel="Population", ylabel="Rate")

Instead of a scatter plot with an illustration of linear regression, I'm seeing the following in the browser:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In [1], line 1
----> 1 import seaborn as sns
      3 ## data from Utts ch. 9 exercise 9 (table 9.3)
      4 
      5 # year = [1982, 1983, 1985, 1986, 1987, 1988, 1989, 1990, 1991]
      6 pop = [231, 234, 239, 241, 243, 246, 248, 249, 252]

ModuleNotFoundError: No module named 'seaborn'

The seaborn bundle is listed in the requirements.txt for the project. I've verified that seaborn is being installed during the GitHub Actions workflow. However, it seems that it's not showing up as available in the notebook, after the repository is deployed to the gh-pages site.

Reproduce

  1. Fork the jupyterlite/demo template, via the "Use this template" button or similar GH CLI action.
  2. Ensure the gh-pages support is enabled in the fork
  3. Add seaborn to requirements.txt
  4. Commit the change and visit the gh-pages site once built and deployed
  5. Try to reference seaborn in a notebook at the deployed site

I'm using the pyodide kernel in the notebook

Expected behavior

I was hoping that the graph would show up in JupyterLite on the gh-pages site, similar to how it's rendered with each of my local JuypterLab installations.

Context

This is with the JupyterLite installation from the jupyterlite/demo template at GitHub

I'm certain there are other ways to serve pages on the Web, with JupyterLab. I'm not certain if many of those methods would make for such an easy walkthough though, lol

This illustration was made after a short read-through with Plotting and Visualization, in Python for Data Analysis, 3rd ed.

spchamp commented 1 year ago

Partial Workaround

After adding the following to an individual cell at the start of the page, before any cells containing rendering code, the seaborn package becomes available with later plots being rendered in the page:

%pip install -q seaborn
%matplotlib inline

Having discovered this, I suppose it's a closed bug