nbformat
nbformat copied to clipboard
ImportError with encodestring from package base64
Describe the bug Jupyter experiences a fatal error on startup. ImportError: cannot import name 'encodestring' from 'base64' (/usr/lib/python3.9/base64.py). 'encodestring is a removed function in python 3.9. Apparently this error is caused by nbformat importing base64
To Reproduce Steps to reproduce the behavior:
- Python version 3.9
- Run any Jupyter product (Notebook, lab).
Expected behavior Traceback (most recent call last): File "/home/user/.local/bin/jupyter-notebook", line 5, in from notebook.notebookapp import main File "/home/user/.local/lib/python3.9/site-packages/notebook/notebookapp.py", line 83, in from .services.contents.manager import ContentsManager File "/home/user/.local/lib/python3.9/site-packages/notebook/services/contents/manager.py", line 17, in from nbformat import sign, validate as validate_nb, ValidationError File "/home/user/.local/lib/python3.9/site-packages/nbformat/init.py", line 14, in from . import v1 File "/home/user/.local/lib/python3.9/site-packages/nbformat/v1/init.py", line 19, in from .nbjson import reads as reads_json, writes as writes_json File "/home/user/.local/lib/python3.9/site-packages/nbformat/v1/nbjson.py", line 19, in from base64 import encodestring ImportError: cannot import name 'encodestring' from 'base64' (/usr/lib/python3.9/base64.py)
Desktop (please complete the following information):
- OS: Manjaro 20.12.2 Gnome 3.38.4
- Browser Firefox 86.0.01-01
- Jupyter 4.4.0
@Alonoparag what version of nbformat are you using?
I have experienced a very similar bug using Python 3.9, nbformat 5.1.3 I used to be able to run python 3.9 fine.
File "/Users/ralphbird/miniconda3/envs/default/bin/jupyter-lab", line 6, in <module>
from jupyterlab.labapp import main
File "/Users/ralphbird/miniconda3/envs/default/lib/python3.9/site-packages/jupyterlab/__init__.py", line 7, in <module>
from .labapp import LabApp
File "/Users/ralphbird/miniconda3/envs/default/lib/python3.9/site-packages/jupyterlab/labapp.py", line 15, in <module>
from jupyterlab_server import slugify, WORKSPACE_EXTENSION
File "/Users/ralphbird/miniconda3/envs/default/lib/python3.9/site-packages/jupyterlab_server/__init__.py", line 4, in <module>
from .app import LabServerApp
File "/Users/ralphbird/miniconda3/envs/default/lib/python3.9/site-packages/jupyterlab_server/app.py", line 7, in <module>
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
File "/Users/ralphbird/miniconda3/envs/default/lib/python3.9/site-packages/jupyter_server/extension/application.py", line 21, in <module>
from jupyter_server.serverapp import ServerApp
File "/Users/ralphbird/miniconda3/envs/default/lib/python3.9/site-packages/jupyter_server/serverapp.py", line 74, in <module>
from jupyter_server.services.contents.manager import AsyncContentsManager, ContentsManager
File "/Users/ralphbird/miniconda3/envs/default/lib/python3.9/site-packages/jupyter_server/services/contents/manager.py", line 17, in <module>
from nbformat import sign, validate as validate_nb, ValidationError
File "/Users/ralphbird/miniconda3/envs/default/lib/python3.9/site-packages/nbformat/__init__.py", line 14, in <module>
from . import v1
File "/Users/ralphbird/miniconda3/envs/default/lib/python3.9/site-packages/nbformat/v1/__init__.py", line 19, in <module>
from .nbjson import reads as reads_json, writes as writes_json
File "/Users/ralphbird/miniconda3/envs/default/lib/python3.9/site-packages/nbformat/v1/nbjson.py", line 19, in <module>
from base64 import encodestring
ImportError: cannot import name 'encodestring' from 'base64' (/Users/ralphbird/miniconda3/envs/default/lib/python3.9/base64.py)
Rolling back to nbversion 5.1.2 fixed the issue. I am running through conda on a macOS Cataliina (10.15.7) and have quite a large environment (I have not tested a minimal environment yet I am afraid).
As an informational point, encodestring
has not been in use in nbformat.v1.json
since version 5.0.0. If you are seeing this error, it is likely you are still on version 4.x of nbconvert. If there is something preventing you from updating to the 5.x strain while on a recent version of Python, please comment why. Maybe if the case seems important enough, you can convince someone that a backported fix to 4.x is needed.
@ralphbird It seems likely that you are not actually getting version 5.1.3. Please inspect the code in your env to verify the version string in your installed package.