Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel error win32api #4980

Closed
lueenavarro opened this issue Oct 17, 2019 · 27 comments
Closed

Kernel error win32api #4980

lueenavarro opened this issue Oct 17, 2019 · 27 comments

Comments

@lueenavarro
Copy link

lueenavarro commented Oct 17, 2019

After launching any notebook, I get the following error.

Traceback (most recent call last):
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\tornado\web.py", line 1699, in _execute
    result = await result
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 742, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\notebook\services\sessions\handlers.py", line 72, in post
    type=mtype))
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 735, in run
    value = future.result()
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 742, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "C:\Users\lnavarro6\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\lnavarro6\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 735, in run
    value = future.result()
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 742, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "C:\Users\lnavarro6\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\lnavarro6\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 735, in run
    value = future.result()
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 209, in wrapper
    yielded = next(result)
  File "C:\Users\lnavarro6\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\lnavarro6\AppData\Roaming\Python\Python37\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
    km.start_kernel(**kwargs)
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\jupyter_client\manager.py", line 240, in start_kernel
    self.write_connection_file()
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\jupyter_client\connect.py", line 476, in write_connection_file
    kernel_name=self.kernel_name
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\jupyter_client\connect.py", line 141, in write_connection_file
    with secure_write(fname) as f:
  File "C:\Users\lnavarro6\AppData\Local\Continuum\anaconda3\lib\contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\jupyter_core\paths.py", line 404, in secure_write
    win32_restrict_file_to_user(fname)
  File "C:\Users\lnavarro6\AppData\Roaming\Python\Python37\site-packages\jupyter_core\paths.py", line 359, in win32_restrict_file_to_user
    import win32api
ImportError: DLL load failed: The specified procedure could not be found.
@kevin-bates
Copy link
Member

Rumors abound there's an installation glitch in the 225 build of pywin32. Have you tried conda install pywin32?

@afvca
Copy link

afvca commented Oct 17, 2019

Don't know how you installed pywin32, but you may be missing the system files.

Try downloading a precompiled wheel from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32

And install pywin32 system files, cd into your PYTHONPATH, and run python.exe Scripts/pywin32_postinstall.py -install from an elevated command prompt.

@ValentinVerschinin
Copy link

ValentinVerschinin commented Jan 24, 2020

Had the same issue and pip uninstall pywin32 and installing it again helped. conda install pywin32 didn't work, however.

@JStuckner
Copy link

Can confirm @ValentinVerschinin solution worked. Thanks for trouble shooting this several hours before me!

@Besong
Copy link

Besong commented Mar 5, 2020

Thanks @ValentinVerschinin it worked!.

@mcmah309
Copy link

According to pywin32 github you must run

pip install pywin32

and after that, you must run

python [environment path]/Scripts/pywin32_postinstall.py -install

After hours this worked for me!

@eren-korkmaz
Copy link

According to pywin32 github you must run

pip install pywin32

and after that, you must run

python [environment path]/Scripts/pywin32_postinstall.py -install

After hours this worked for me!

İt worked too

@kbyokin
Copy link

kbyokin commented Jul 8, 2020

According to pywin32 github you must run

pip install pywin32

and after that, you must run

python [environment path]/Scripts/pywin32_postinstall.py -install

After hours this worked for me!

It also worked for me. Cheers bro!

@kevin-bates
Copy link
Member

Too many successes - time to close! 😄

@ManuelZ
Copy link

ManuelZ commented Jul 25, 2020

The easiest thing for me was to pip uninstall it and then conda install it.

@naveen1973
Copy link

Re.: python [environment path]/Scripts/pywin32_postinstall.py -install

How do I find out what I have to type where it states [environment path]?
Do I have to type this in the CMD prompt: "(base) C:\Users\User" ?

@pembeci
Copy link

pembeci commented Nov 16, 2020

Yes, you need to run it in command prompt and after activating the environment where you did install pywin32. If you are using miniconda and you installed it in base environment it will be:

C:\Users\<USERNAME>\miniconda3\Scripts

if you used another environment first activate it and then try to locate the script in:

C:\Users\<USERNAME>\miniconda3\envs\<ENV_NAME>\Scripts

If you are using virtualenv then try to find the script in that environment's folder.

@naveen1973
Copy link

When I go to
"(base) C:\Users\User>"
I type in "cd miniconda" but I am getting this error message:
"The system cannot find the path specified."
What happened there?

@vinodhmano
Copy link

conda install pywin32 worked for me. I am using Python 3.8

@johann-petrak
Copy link

johann-petrak commented Jan 31, 2021

Why is this bug closed? According to this:
mhammond/pywin32#1507
the problem arises because of the way how Jupyter bundles the library.

I just got this problem after installing jupyter into a brand now Miniconda installagion, creating a Python 3.9 environment for my packages (On Windows 10)

I think it is unacceptable for Windows users to run into the problem of the kernel not working in Jupyter, googling the problem, finding a closed issue, figuring out some installation/environment path on their computer, and then needing to type in a cryptic command in order to make things work for them.

This should get fixed properly.

@kevin-bates
Copy link
Member

Thanks @johann-petrak - your point is valid. Rather than re-open this issue, I would suggest a new issue be opened in jupyter_core which is responsible for the pywin32 requirement within the ecosystem.

Please reference your previous comment as to what the issue is. I suspect this will require some conda expertise if I'm understanding the recommendation.

Also, note that Terminal functionality is currently not working in Windows with Python 3.9+ (#5967).

@mjstenbe
Copy link

mjstenbe commented May 5, 2021

This issue is still valid for the latest version of Anaconda.

@Ilia-Kosenkov
Copy link

Don't know how you installed pywin32, but you may be missing the system files.

Try downloading a precompiled wheel from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32

And install pywin32 system files, cd into your PYTHONPATH, and run python.exe Scripts/pywin32_postinstall.py -install from an elevated command prompt.

Just want to confirm that this solution did work for my conda environment.

For those unable to find Scripts folder or have no PYTHONPATH

This will likely require an elevated (administrator) prompt
Once you activated your environment, a correct path to python.exe is prepended to your PATH variable.
On Windows, you can locate executables found in PATH directories using the following command:
where.exe python.exe
Please note that if you run it from PowerShell, you have to explicitly type where.exe, as where will resolve to Where-Object, a different utility.
You will get a list of all absolute paths to python.exe, select the first one, like:

C:\tools\miniconda3\envs\my_env\python.exe  

cd to the folder containing python.exe by e.g. copy-pasting part of the path you got from running the previous command.
From there you can run python.exe Scripts/pywin32_postinstall.py -install as-is.

@mtachaudhary
Copy link

Faced the same issue and fixed it now.

Please follow these steps:

  1. Install pywin32 using conda install pywin32, and
  2. Uninstall pywin32 using pip uninstall pywin32

I think the issue is, pip pywin32 was conflicting with conda

@johann-petrak
Copy link

Interesting possible workaround but not a fix.

@bosukeme
Copy link

I just did pip install pywin32

Then did jupyter notebook again, and it worked

@jvilcan
Copy link

jvilcan commented Jun 11, 2021

Faced the same issue and fixed it now.

Please follow these steps:

  1. Install pywin32 using conda install pywin32, and
  2. Uninstall pywin32 using pip uninstall pywin32

I think the issue is, pip pywin32 was conflicting with conda

It works for me.

@JEEZzKnight
Copy link

No it does not work even after installing the pywin32

when you install conda and then download vscode the kernal dir have been changed in vscode jupyter from anaconda jupyter that why it shows win32api error

you just have to change kernal dir back to conda jupyter notebook

@cgohlke
Copy link
Contributor

cgohlke commented Aug 3, 2021

FWIW, jupyter/jupyter_core#230 replaces pywin32 with ctypes. No more win32api import errors and works on Python 3.10 and PyPy...

@Arnab1181412
Copy link

python [environment path]/Scripts/pywin32_postinstall.py -install

Working Awesome

@EulersNumber
Copy link

EulersNumber commented Mar 19, 2022

How can this still be an issue in 2022...? Can't believe annoying bugs like these aren't fixed.

Luckily after banging my head on the wall for a good while by trying all the tens of different proposed solutions, I did the same as @ValentinVerschinin and it worked.

Just annoying that so many people have to deal with this issue even though it has been known for so long.

@cgohlke
Copy link
Contributor

cgohlke commented Mar 19, 2022

How can this still be an issue in 2022...?

Because the installation of pywin32 using wheels is fundamentally broken and requires manual pre- and/or post-install steps.

Can't believe annoying bugs like these aren't fixed.

The original issue was fixed in jupyter_core 4.8.

Please provide the package versions and a full traceback. There might be packages other than jupyter_core that depend on pywin32 and fail to import if the pywin32 installation is incomplete or corrupted.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests