jupyter notebook showing this message, ImportError: cannot import name 'encodestring' from 'base64'

Question:

I am new to python and jupyter notebook and I am using windows. Recently I installed Anaconda Navigator 2.3.1 and the python verson 3.9.13 on my computer. After entering the command jupyter notebook on the command-line, my browser doesn’t open jupyter notebook, instead that showing me this error message:

(base) C:UsersUSER>jupyter notebook
Traceback (most recent call last):
  File "D:Anaconda3anaconda3Scriptsjupyter-notebook-script.py", line 6, in <module>
    from notebook.notebookapp import main
  File "D:Anaconda3anaconda3libsite-packagesnotebooknotebookapp.py", line 79, in <module>
    from .services.contents.manager import ContentsManager
  File "D:Anaconda3anaconda3libsite-packagesnotebookservicescontentsmanager.py", line 17, in <module>
    from nbformat import sign, validate as validate_nb, ValidationError
  File "C:UsersUSERAppDataRoamingPythonPython39site-packagesnbformat__init__.py", line 14, in <module>
    from . import v1
  File "C:UsersUSERAppDataRoamingPythonPython39site-packagesnbformatv1__init__.py", line 19, in <module>
    from .nbjson import reads as reads_json, writes as writes_json
  File "C:UsersUSERAppDataRoamingPythonPython39site-packagesnbformatv1nbjson.py", line 19, in <module>
    from base64 import encodestring
ImportError: cannot import name 'encodestring' from 'base64' (D:Anaconda3anaconda3libbase64.py)

I don’t understand what should do now? And how to solve this issue! Please help……….

Asked By: Monidipa Das

||

Answers:

base64.encodestring was deprecated since python 3.1 and finally removed in 3.9

You can compare the official documentation for the base64 library for version 3.8 and 3.9

https://docs.python.org/3.8/library/base64.html
https://docs.python.org/3.9/library/base64.html

I’m not sure exactly how you installed anaconda navigator but i would suggest using the latest distribution of anaconda which includes navigator

Answered By: OranShuster

This error is caused by nbformat. Check your nbformat with the command ‘pip freeze’, and look for the nbformat version. Most likely your version is anterior to 5.1.3.

Upgrade to that version with the following command:

pip3 install nbformat==5.1.3

or just ‘pip install nbformat==5.1.3’ ; depending on your configuration.

It should fix the issue.

Francis Massolin
Services that grow your business!

Answered By: Francis Massolin