Import error while trying to run jupyter notebook
Asked Answered
C

5

4

An import error occurs when trying to run jupyter notebook

I'm trying to run jupyter notebook using anaconda (git bash platform), and as I type in jupyter notebook, an import error occurs every time. I tried to lauch it inside an environment, but the same error occured.

$ jupyter notebook

Traceback (most recent call last):

File "C:\Users\User\Anaconda3\Scripts\jupyter-notebook-script.py", line 6, in
 <module>
from notebook.notebookapp import main
File "C:\Users\User\Anaconda3\lib\site-packages\notebook\notebookapp.py", line 47, in <module>
from zmq.eventloop import ioloop
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\__init__.py", line 47, in <module>
from zmq import backend
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\backend\__init__.py", line 40, in <module>
reraise(*exc_info)
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\utils\sixcerpt.py", line 34, in reraise
raise value
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\backend\__init__.py", line 27, in <module>
_ns = select_backend(first)
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\backend\select.py", line 27, in select_backend
mod = __import__(name, fromlist=public_api)
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
from . import (constants, error, message, context,
    ImportError: DLL load failed: The specified module could not be found.

EDITED After reinstalling pyzmq (and I tried reinstalling conda too), the following error occurs:

$ jupyter notebook

Traceback (most recent call last): File "C:\Users\User\Anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 10, in import sqlite3

File "C:\Users\User\Anaconda3\lib\sqlite3__init__.py", line 23, in from sqlite3.dbapi2 import *

File "C:\Users\User\Anaconda3\lib\sqlite3\dbapi2.py", line 27, in

from _sqlite3 import *

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\User\Anaconda3\Scripts\jupyter-notebook-script.py", line 6, in

from notebook.notebookapp import main

File "C:\Users\User\Anaconda3\lib\site-packages\notebook\notebookapp.py", line 86, in

from .services.sessions.sessionmanager import SessionManager

File "C:\Users\User\Anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 13, in

from pysqlite2 import dbapi2 as sqlite3

ModuleNotFoundError: No module named 'pysqlite2'

Chantalchantalle answered 16/1, 2019 at 20:35 Comment(1)
That's python unable to import sqlite3. Can you do that in an interactive interpreter?Inshrine
C
13

I found a similar issue open on GitHub for zmq. The recommendation by GitHub user harsh23tyagi that seems to work for most is to run the following:

pip uninstall pyzmq
pip install pyzmq
Creaky answered 16/1, 2019 at 20:41 Comment(3)
Thanks, it partially solved my problem, I've edited my question with the now error...Chenay
@BenedekDér Try running pip install pysqlite2 to see if it resolves that errorCreaky
This resolves an issue which appears in various different forms, related to zmq, pywin32, Pycharm and Anaconda (64-bit). In my case, when I was starting Jupyter from the Anaconda base environment everything worked normally. With other environments I would get an error, even if jupyter notebook was invoked from Anaconda Prompt, independent of Pycharm. Setting up a clean environment only, didn't help. What did help was setting up a clean environment and then running the uninstall/install of pyzmq with pip, from the terminal, within the activated environment.Screening
W
3

Working with conda env, jupyter notebook worked in (base) env but gave the .libzmq error in (my_env). To be able to run notebooks from my_env, this worked for me :

  • pip uninstall pyzmq
  • pip install pyzmq==20 (no version for pyzmq didn't fix the issue for me)
Warhol answered 22/1, 2021 at 22:29 Comment(0)
U
0

It seems that updating pyzmq to the latest version fixes this problem for me.

conda install pyzmq=22
Uvarovite answered 10/3, 2021 at 5:25 Comment(0)
D
0
  • Open Anaconda Navigator

  • Go to Jupyter Notebook Setting (icon on the right hand side corner)

  • And select install specific version After installation select new installation and open it. It will work !!

Denouement answered 9/8, 2023 at 8:19 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Matthias
P
0

This is due to a change in module structure with jupyter notebook version 7. Downgrading the notebook version to 6.5 worked for me. Maybe this can work pip3 install notebook==6.5.5

Pistol answered 22/1 at 19:11 Comment(1)
At the time the OP was posted, this didn't involve Jupyter Notebook 7+ as it didn't exist. Additionally, the original post was directed at using the Aanconda distribution and you should hesitate to ever advise using pip to install anything where there is Anaconda/conda recipe. The choice was made to use Anaconda/conda as the primary package manager and that should always be the primary way to adjust the environment(s).Pyrophyllite

© 2022 - 2024 — McMap. All rights reserved.