Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

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

Closed
jtpio opened this issue Mar 31, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@jtpio
Copy link
Member

jtpio commented Mar 31, 2023

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
Copy link
Member Author

jtpio commented Apr 20, 2023

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 jupyter/nbformat#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 jupyter/nbformat#304 fixes the issue: https://github.com/jupyter/nbformat/releases/tag/5.5.0

image

@jtpio
Copy link
Member Author

jtpio commented Apr 20, 2023

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
Copy link
Member Author

jtpio commented Sep 7, 2023

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

image

Closing as fixed by emscripten-forge/empack#82, thanks!

@jtpio jtpio closed this as completed Sep 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant