'Why do I have a Kernel Error in Jupyter Notebook?

I am a newbie to python. I am getting the below error in Kernel while opening jupyter notebook. Any ideas how I can resolve it? Installation of jupyter has been done via Anaconda3 - tried reinstalling and setting environment variables, but no luck so far. Any help would be greatly appreciated.

 Traceback (most recent call last):
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\web.py", line 1699, in _execute
        result = await result
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\notebook\services\sessions\handlers.py", line 72, in post
        type=mtype))
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 735, in run
        value = future.result()
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\notebook\services\sessions\sessionmanager.py", line 88, in create_session
        kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 735, in run
        value = future.result()
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\notebook\services\sessions\sessionmanager.py", line 101, in start_kernel_for_session
        self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 735, in run
        value = future.result()
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 209, in wrapper
        yielded = next(result)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\notebook\services\kernels\kernelmanager.py", line 168, in start_kernel
        super(MappingKernelManager, self).start_kernel(**kwargs)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
        km.start_kernel(**kwargs)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\manager.py", line 240, in start_kernel
        self.write_connection_file()
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\connect.py", line 547, in write_connection_file
        kernel_name=self.kernel_name
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\connect.py", line 212, in write_connection_file
        with secure_write(fname) as f:
      File "C:\Users\drag88\Anaconda3\lib\contextlib.py", line 112, in __enter__
        return next(self.gen)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\connect.py", line 100, in secure_write
        win32_restrict_file_to_user(fname)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\connect.py", line 53, in win32_restrict_file_to_user
        import win32api
    ImportError: DLL load failed: The specified procedure could not be found.


Solution 1:[1]

  • Step 2 command: conda activate (location of your env folder)
  • Step 3 command: python -m ipykernel install --user

Works for Windows.

Solution 2:[2]

If you have Python installed on your pc run from cmd or powershell:

pip install jupyterlab

Then you can start it with:

jupyter lab

Solution 3:[3]

The installation might have missed some steps which are fixed by post_install. Go to yout venv's Script directory and run the command

python .\pywin32_postinstall.py -install

Make sure you are running the shell with Admin rights.

Solution 4:[4]

This error is sometimes as a result of the deleted environment that was created before. For Windows users, run the following code in cmd

python -m ipykernel install –user

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 סטנלי גרונן
Solution 2 Christophermp
Solution 3 Shivam Batra
Solution 4 Happy N. Monday