jupyterlite / xeus-python-kernel

xeus-python in JupyterLite
https://xeus-python-kernel.readthedocs.io
BSD 3-Clause "New" or "Revised" License
30 stars 19 forks source link

`import nbformat` gives: `TypeError: expected string or bytes-like object` #120

Closed jtpio closed 1 year ago

jtpio commented 1 year ago

Description

Building a fresh JupyterLite site with nbformat as a dependency gives the following issue:

image

Reproduce

  1. Create environment.yml with the following content:
name: test
channels:
- https://repo.mamba.pm/emscripten-forge
- https://repo.mamba.pm/conda-forge
dependencies:
- nbformat
  1. Create a new virtual environment for the build
  2. python -m pip install jupyterlite-xeus-python
  3. jupyter lite build
  4. jupyter lite serve
  5. Open http://localhost:8000/_output/lab/index.html

Expected behavior

It should be possible to import nbformat.

Context

This came up when checking if plotly works with the xeus python kernel in JupyterLite:

import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Scatter(y=[2, 1, 4, 3]))
fig.add_trace(go.Bar(y=[1, 4, 3, 2]))
fig.update_layout(title="Hello Figure")
fig.show()

image

jtpio commented 1 year ago

It seems because nbformat uses importlib.metadata for find the version: https://github.com/jupyter/nbformat/blob/633a433d13436247c5994f571911c74a1ec507d4/nbformat/_version.py#L5-L10

This change happened in https://github.com/jupyter/nbformat/pull/304

In the xeus python kernel doing something similar to find the version of pandas returns None:

image

Pinning on nbformat=5.5.0 which is the version just before https://github.com/jupyter/nbformat/pull/304 fixes the issue: https://github.com/jupyter/nbformat/releases/tag/5.5.0

image

jtpio commented 1 year ago

In the xeus python kernel doing something similar to find the version of pandas returns None:

Although it's not clear why importlib.metadata.version returns None.

jtpio commented 1 year ago

Just tried with the latest empack==3.1.4 and it seems to be fixing the issue.

image

Closing as fixed by https://github.com/emscripten-forge/empack/pull/82, thanks!