Jupyter Notebook cells don't run!

Hi,
I am new to jupyter notebook and I have just started learning ML. Since I have started to use jupyter notebook I have seen that my cells don’t run! I press shift-enter and rather than the targeted cell running, the targeted cell moves down. It shows a kernel error on the top right and when I click it I get this error message:
Traceback (most recent call last):
File “C:\Users\shiva\anaconda3\lib\site-packages\tornado\web.py”, line 1703, in _execute
result = await result
File “C:\Users\shiva\anaconda3\lib\site-packages\tornado\gen.py”, line 742, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File “C:\Users\shiva\anaconda3\lib\site-packages\notebook\services\sessions\handlers.py”, line 69, in post
model = yield maybe_future(
File “C:\Users\shiva\anaconda3\lib\site-packages\tornado\gen.py”, line 735, in run
value = future.result()
File “C:\Users\shiva\anaconda3\lib\site-packages\tornado\gen.py”, line 742, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File “C:\Users\shiva\anaconda3\lib\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\shiva\anaconda3\lib\site-packages\tornado\gen.py”, line 735, in run
value = future.result()
File “C:\Users\shiva\anaconda3\lib\site-packages\tornado\gen.py”, line 742, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File “C:\Users\shiva\anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py”, line 100, in start_kernel_for_session
kernel_id = yield maybe_future(
File “C:\Users\shiva\anaconda3\lib\site-packages\tornado\gen.py”, line 735, in run
value = future.result()
File “C:\Users\shiva\anaconda3\lib\site-packages\tornado\gen.py”, line 209, in wrapper
yielded = next(result)
File “C:\Users\shiva\anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py”, line 168, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File “C:\Users\shiva\anaconda3\lib\site-packages\jupyter_client\multikernelmanager.py”, line 186, in start_kernel
km.start_kernel(**kwargs)
File “C:\Users\shiva\anaconda3\lib\site-packages\jupyter_client\manager.py”, line 304, in start_kernel
kernel_cmd, kw = self.pre_start_kernel(**kw)
File “C:\Users\shiva\anaconda3\lib\site-packages\jupyter_client\manager.py”, line 251, in pre_start_kernel
self.write_connection_file()
File “C:\Users\shiva\anaconda3\lib\site-packages\jupyter_client\connect.py”, line 468, in write_connection_file
self.connection_file, cfg = write_connection_file(self.connection_file,
File “C:\Users\shiva\anaconda3\lib\site-packages\jupyter_client\connect.py”, line 138, in write_connection_file
with secure_write(fname) as f:
File “C:\Users\shiva\anaconda3\lib\contextlib.py”, line 113, in enter
return next(self.gen)
File “C:\Users\shiva\anaconda3\lib\site-packages\jupyter_core\paths.py”, line 435, in secure_write
win32_restrict_file_to_user(fname)
File “C:\Users\shiva\anaconda3\lib\site-packages\jupyter_core\paths.py”, line 361, in win32_restrict_file_to_user
import win32api
ImportError: DLL load failed while importing win32api: %1 is not a valid Win32 application.

I searched online and found I had to reinstall pywin32 and run this command:
python.exe Scripts/pywin32_postinstall.py -install

But it shows me this error:
(base) PS C:\Users\shiva\anaconda3\Scripts> cd C:\Users\shiva\anaconda3\Scripts\pywin32_postinstall.py
cd : Cannot find path ‘C:\Users\shiva\anaconda3\Scripts\pywin32_postinstall.py’ because it does not exist.
At line:1 char:1

  • cd C:\Users\shiva\anaconda3\Scripts\pywin32_postinstall.py
  •   + CategoryInfo          : ObjectNotFound: (C:\Users\shiva\..._postinstall.py:String) [Set-Location], ItemNotFoundE
     xception
      + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
    

Pls help me, I am new to jupyter notebook!

Did you first determine your active Python location for Scripts according to bottom of the documentation here?

where Scripts is located in the active Python’s installation location.

You replace Scripts in that command with that location, I think.

Here has an example in an image under the text ‘And this is how my Python Scripts path looks like:’ showing where the installation was in that Windows example.

This post with the same error spells out the command that actually worked with a similar path. You’ll see in that example there they first used cd to change to location of Scripts and then issued the following while in that directory:

python pywin32_postinstall.py -install

Just noting here mainly for others in a similar boat (and for keeping related topics linked here) that also this thread that lead to this suggestion has an error in the original post looks similar to yours.
But I demoted mention of it because you look well on your way to reinstalling pywin32.

Hi,
First of all thanks a lot for helping me! Sorry but this is my path I am using:
C:\Users\shiva\anaconda3\Scripts

And this is my error message when I run the python pywin32_postinstall.py -install command in the above directory:

(base) PS C:\Users\shiva\anaconda3\Scripts> python pywin32_postinstall.py -install
Parsed arguments are: Namespace(destination=‘C:\Users\shiva\anaconda3\Lib\site-packages’, install=True, quiet=False, remove=False, silent=False, wait=None)
pywin32_postinstall.py:164: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module’s documentation for alternative uses
import imp
Traceback (most recent call last):
File “pywin32_postinstall.py”, line 633, in
install(args.destination)
File “pywin32_postinstall.py”, line 336, in install
import win32api
ImportError: DLL load failed while importing win32api: %1 is not a valid Win32 application.

What shud I do to solve this.
(I am using anaconda not python. I forgot to mention this, sorry)

Anaconda is a distribution of Python. From here:

Anaconda Individual Edition is the world’s most popular Python distribution platform with over 25 million users worldwide.

Try the following based on here:

pip install -- pywin32==227

Hopefully that will work. If not, try the other solutions at that page, such as pip install --upgrade pywin32. This one looks particulary thorough if nothing else has helped:

Then I managed to get it to work by reinstalling anaconda as admin (through right clicking the installer) and then installing it in it’s default path C:\ProgramData\Anaconda3 . I reinstalled it a bunch of times prior to this with no avail, both without admin and with admin directly under C:\ . No idea if installing it in it’s default path as admin did the trick or something entirely different.

But most people say what I put above (or pip install --upgrade pywin32) fixed things.

2 Likes

Thanks a lot! The first solution worked!

1 Like