Kashi
Kashi

Reputation: 109

Jupyter Notebook: Error while connecting to Server

I just installed the latest python version(3.8.5)(Anaconda distribution) while following all the steps correctly as mentioned by the docs.

LINK TO DOCUMENTATION

Then I tried adding it to my Jupyter Notebook using:

python -m ipykernel install --user --name=Python3.8.5

[Python3.8.5 is the name of the environment]

I succeeded in adding it to the jupyter notebook!

But when I'm trying to access it using Jupyter Notebook , this is what it is showing: Here: The traceback in the jupyter notebook command line is as follows:

    To access the notebook, open this file in a browser:
        file:///C:/Users/aakash/AppData/Roaming/jupyter/runtime/nbserver-5272-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=53898b31bc28a966e6576d5e20099d192dc5c95ddff14a4c
     or http://127.0.0.1:8888/?token=53898b31bc28a966e6576d5e20099d192dc5c95ddff14a4c
[I 16:56:48.967 NotebookApp] Creating new notebook in
[I 16:56:57.277 NotebookApp] Kernel started: 09f6bfbd-6e88-4264-a4a3-c975801012bc, name: python3.8.5
Traceback (most recent call last):
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\traitlets\config\application.py", line 836, in launch_instance
    app.initialize(argv)
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\traitlets\config\application.py", line 86, in inner
    return method(app, *args, **kwargs)
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 570, in initialize
    self.write_connection_file()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 230, in write_connection_file
    write_connection_file(cf, ip=self.ip, key=self.session.key, transport=self.transport,
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 138, in write_connection_file
    with secure_write(fname) as f:
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_core\paths.py", line 435, in secure_write
    win32_restrict_file_to_user(fname)
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_core\paths.py", line 361, in win32_restrict_file_to_user
    import win32api
ImportError: DLL load failed while importing win32api: The specified module could not be found.
[I 16:57:00.140 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports
[IPKernelApp] ERROR | Failed to load connection file: 'C:\\Users\\aakash\\AppData\\Roaming\\jupyter\\runtime\\kernel-09f6bfbd-6e88-4264-a4a3-c975801012bc.json'
Traceback (most recent call last):
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 257, in init_connection_file
    self.load_connection_file()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 496, in load_connection_file
    info = json.load(f)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[I 16:57:03.144 NotebookApp] KernelRestarter: restarting kernel (2/5), new random ports
[IPKernelApp] ERROR | Failed to load connection file: 'C:\\Users\\aakash\\AppData\\Roaming\\jupyter\\runtime\\kernel-09f6bfbd-6e88-4264-a4a3-c975801012bc.json'
Traceback (most recent call last):
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 257, in init_connection_file
    self.load_connection_file()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 496, in load_connection_file
    info = json.load(f)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[I 16:57:06.150 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports
[IPKernelApp] ERROR | Failed to load connection file: 'C:\\Users\\aakash\\AppData\\Roaming\\jupyter\\runtime\\kernel-09f6bfbd-6e88-4264-a4a3-c975801012bc.json'
Traceback (most recent call last):
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 257, in init_connection_file
    self.load_connection_file()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 496, in load_connection_file
    info = json.load(f)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[I 16:57:09.159 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
[IPKernelApp] ERROR | Failed to load connection file: 'C:\\Users\\aakash\\AppData\\Roaming\\jupyter\\runtime\\kernel-09f6bfbd-6e88-4264-a4a3-c975801012bc.json'
Traceback (most recent call last):
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 257, in init_connection_file
    self.load_connection_file()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 496, in load_connection_file
    info = json.load(f)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[W 16:57:12.163 NotebookApp] KernelRestarter: restart failed
[W 16:57:12.163 NotebookApp] Kernel 09f6bfbd-6e88-4264-a4a3-c975801012bc died, removing from map.
[W 16:57:57.333 NotebookApp] Timeout waiting for kernel_info reply from 09f6bfbd-6e88-4264-a4a3-c975801012bc
[E 16:57:57.333 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: 09f6bfbd-6e88-4264-a4a3-c975801012bc)
[W 16:57:58.366 NotebookApp] 404 GET /api/kernels/09f6bfbd-6e88-4264-a4a3-c975801012bc/channels?session_id=7b5b1d566bd249d981caaf4631317e38 (::1): Kernel does not exist: 09f6bfbd-6e88-4264-a4a3-c975801012bc
[W 16:57:58.400 NotebookApp] 404 GET /api/kernels/09f6bfbd-6e88-4264-a4a3-c975801012bc/channels?session_id=7b5b1d566bd249d981caaf4631317e38 (::1) 35.90ms referer=None
[W 16:58:00.426 NotebookApp] Replacing stale connection: 09f6bfbd-6e88-4264-a4a3-c975801012bc:7b5b1d566bd249d981caaf4631317e38
[I 16:58:57.356 NotebookApp] Saving file at /Untitled5.ipynb
[W 17:02:05.348 NotebookApp] Replacing stale connection: 09f6bfbd-6e88-4264-a4a3-c975801012bc:7b5b1d566bd249d981caaf4631317e38
[W 17:06:13.365 NotebookApp] Replacing stale connection: 09f6bfbd-6e88-4264-a4a3-c975801012bc:7b5b1d566bd249d981caaf4631317e38

I looked at every available solution on github and stackoverflow but none provided a clear solution. Please help me out!! [I'm on windows]

Please suggest the necessary steps! I'm in dire need of help!!! Edit: Solutions like downgrading tornado, downgrading conda etc are not working!! I have tried updating all the package even that is not working!

Upvotes: 2

Views: 3956

Answers (2)

Wouter
Wouter

Reputation: 3271

If you're in a Conda environment, try:

conda install pywin32

Upvotes: 1

Ali A. Noroozi
Ali A. Noroozi

Reputation: 81

First, you need to install pywin32 in the new environment:

conda activate Python3.8.5
pip install pywin32

Then, try registering pywin32 with the system. You just need to open Anaconda Prompt as administrator, navigate to C:\Users\aakash\anaconda3\envs\Python3.8.5\Scripts by running:

cd C:\Users\aakash\anaconda3\envs\Python3.8.5\Scripts

and run the following commands:

conda activate Python3.8.5
python pywin32_postinstall.py -install

Finally, re-open Jupyter Notebook and you're good to go.

Upvotes: 1

Related Questions