Repository: widgetti/ipyvolume (language: python)

Issue:
Ipyvolume cannot be imported in Jupyterlite: KeyError: 'emscripten'
## Reproduce

- Open https://jupyter.org/try-jupyter/lab/
- Open a new notebook
- run a cell containing

```python
import piplite
await piplite.install('ipyvolume')
```

- run a cell containing

```python
import ipyvolume
```

![image](https://user-images.githubusercontent.com/42288570/216800094-70d61de8-297a-4320-8e9b-3ef19033a6ae.png)

```bash
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[2], line 1
----> 1 import ipyvolume

File /lib/python3.10/site-packages/ipyvolume/__init__.py:6
      4 from ipyvolume import styles  # noqa: F401
      5 from ipyvolume import examples  # noqa: F401
----> 6 from ipyvolume import datasets  # noqa: F401
      7 from ipyvolume import embed  # noqa: F401
      8 from ipyvolume.widgets import *  # noqa: F401, F403

File /lib/python3.10/site-packages/ipyvolume/datasets.py:13
      9     from urllib.request import urlretrieve  # py3
     11 import numpy as np
---> 13 osname = dict(darwin="osx", linux="linux", windows="windows")[platform.system().lower()]
     14 data_dir = os.path.expanduser("~/.ipyvolume/datasets")
     15 if not os.path.exists(data_dir):

KeyError: 'emscripten'
```

## Context

I am trying to improve the user experience of running [Panel](https://panel.holoviz.org/) in [its custom build](https://panel.holoviz.org/user_guide/Running_in_Webassembly.html#setting-up-jupyterlite) of Jupyterlite called [Panelite](https://panelite.holoviz.org/) in [Panel #4388](https://github.com/holoviz/panel/pull/4388).

Now I am working with the notebook `reference/panes/IPyWidget.ipynb` which needs to `import ipyvolume`. But it fails.


Discussion / hints:
@MarcSkovMadsen 

don't know if it helps. But this is what I am doing in JupyterLite:

```
# cell 1
%pip install -q ipywidgets plotly ipyvolume ipython_genutils

# cell 2
def PatchIPyVolume(filename="/lib/python3.10/site-packages/ipyvolume/datasets.py"):
    # osname = dict(darwin="osx", linux="linux", windows="windows")[platform.system().lower()]
    with open(filename,"r") as f: lines=f.readlines()
    lines=["osname = platform.system().lower()\n" if line.startswith("osname =") else line for line in lines]
    with open(filename,"w") as f: f.writelines(lines)
PatchIPyVolume()

# cell3
import ipyvolume as ipv
```

Fix patch:
diff --git a/ipyvolume/datasets.py b/ipyvolume/datasets.py
index 0c673bb..164ee74 100644
--- a/ipyvolume/datasets.py
+++ b/ipyvolume/datasets.py
@@ -1,6 +1,6 @@
-import os
 import bz2
 import gzip
+import os
 import platform
 
 try:
@@ -10,10 +10,14 @@
 
 import numpy as np
 
-osname = dict(darwin="osx", linux="linux", windows="windows")[platform.system().lower()]
+osname = platform.system().lower()
+osname = dict(darwin="osx", linux="linux", windows="windows").get(osname, osname)
 data_dir = os.path.expanduser("~/.ipyvolume/datasets")
 if not os.path.exists(data_dir):
-    os.makedirs(data_dir)
+    try:
+        os.makedirs(data_dir, exist_ok=True)
+    except Exception:
+        pass
 
 
 class UrlCached(object):


Test patch:
diff --git a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_0.png b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_0.png
index a8c2efe..852c456 100644
Binary files a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_0.png and b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_0.png differ
diff --git a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_1.png b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_1.png
index a8c2efe..852c456 100644
Binary files a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_1.png and b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_1.png differ
diff --git a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_2.png b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_2.png
index 9e66a8c..98efe8d 100644
Binary files a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_2.png and b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_2.png differ
diff --git a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_3.png b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_3.png
index 214e815..47c2b1c 100644
Binary files a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_3.png and b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_3.png differ
diff --git a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_4.png b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_4.png
index 2056eb4..c070d9b 100644
Binary files a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_4.png and b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_4.png differ
diff --git a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_5.png b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_5.png
index 0c417f2..526ad85 100644
Binary files a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_5.png and b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_5.png differ
diff --git a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_6.png b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_6.png
index b9f092a..acd04d2 100644
Binary files a/ui-tests/reference-output/screenshots/lighting_ipynb_cell_6.png and b/ui-tests/reference-output/screenshots/lighting_ipynb_cell_6.png differ
diff --git a/ui-tests/reference-output/screenshots/scatter_ipynb_cell_0.png b/ui-tests/reference-output/screenshots/scatter_ipynb_cell_0.png
index 4968957..62fc883 100644
Binary files a/ui-tests/reference-output/screenshots/scatter_ipynb_cell_0.png and b/ui-tests/reference-output/screenshots/scatter_ipynb_cell_0.png differ