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

Jupyter Notebook crash with "ImportError: DLL load failed: The specified procedure could not be found" #1409

Closed
JindiXu opened this issue Sep 19, 2019 · 8 comments

Comments

@JindiXu
Copy link

JindiXu commented Sep 19, 2019

  • Expected behavior and actual behavior.
    Jupyter Notebook crashes when installed under pywin32==225

  • using python 3.6.8, 32bit, windows 10, install only jupyter==1.0.0

  • Error:
    import win32api
    ImportError: DLL load failed: The specified procedure could not be found.

@mhammond
Copy link
Owner

mhammond commented Sep 22, 2019

Can you try importing pywintypes and verifying that pywintypes.__path__ is the one from the 225 build? See also #1406

@surfaceowl
Copy link

+1 for this issue

I encountered this same problem today after an install into a new virtualenv. There is a healthy amount of comment traffic in this thread discussing sudden kernel errors in jupyter notebook. I am running Windows 10 Version 1903 for x64.
Downgrade with pip install --upgrade pywin32==224 --force-reinstall fixed it for me.

@mhammond
Copy link
Owner

mhammond commented Oct 5, 2019

I can't do much here unless someone is willing to help answer my question above :(

@surfaceowl
Copy link

@mhammond – I’m glad to help. Please review my notes below, and let me know how else I can help.

Here is what I found today:

Under certain conditions, pywin32==225 causes jupyter notebooks to fail due to ImportError: DLL load failed: when users system is configured such that pywintypes is found under this path: C:\\ProgramData\\Anaconda3\\Library\\bin\\pywintypes37.dll.

One config that causes this error:

  • both Python and Anaconda installed on the Windows system,
  • Results below were confirmed on: OS=Win10 Version 1903 x64
  • Issue occurs both in and outside of a virtualenvironment




More detail
Under these conditions jupyter notebook / Python finds the pywintypes which Anaconda installed under: 'C:\ProgramData\Anaconda3\Library\bin\pywintypes37.dll'… rather than the path under the virtualenvironment which is what happens on correctly working systems.

  • The solution was downgrading to v224 with pip install pywin32==224 …adding force-reinstall worked as well.

The error was not replicated when:

  • User has only installed Python from Python Software Foundation, using their Windows Installer,
  • If the user has both Python and Anaconda installed BUT pywin32==224 is installed

**Other notes:** In a system without Anaconda, both pywin32==224 and pywin32==225 work correctly. In this case, the path to `pywintypes` is something like: `{path_to_your_sample_project}\\venv\\lib\\site-packages\\pywin32_system32\\pywintypes37.dll'`

Systems with Anaconda, have pywintypes path like: C:\\ProgramData\\Anaconda3\\Library\\bin\\pywintypes37.dll


Steps to reproduce:

ENVIRONMENT 1 – only Python (from PSF) v3.7.4 installed
0 – check if pywin32 is installed in system python:
"""
C:\dev\python_visualizations [master +0 ~0 -0]> python Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import pywintypes
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'pywintypes'
"""
RESULT: Expected result, pywintypes is not in the system python

1- Switch to virtualenv and check which version of pywin32 is installed
C:\dev\python_visualizations [master +0 ~0 -0]>(venv) pip install pywin32==225 Requirement already satisfied: pywin32==225 in c:\dev\python_visualizations\venv\lib\site-packages (225)

2- Check pywintypes path in virtualenv for a project that uses jupyter
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import pywintypes
pywintypes
<module 'pywintypes' (C:\dev\python_visualizations\venv\lib\site-packages\pywin32_system32\pywintypes37.dll)>
import inspect
inspect.getfile(pywintypes)
'C:\dev\python_visualizations\venv\lib\site-packages\pywin32_system32\pywintypes37.dll'

RESULT: Jupyter notebook works in this environment when pywin32==225 is installed. Reverting to pywin32==224 also works with Jupyter notebook.

jupyter_pywin32==224

ENVIRONMENT 2 – Anaconda installed alongside Python

3- Check another system, this one using venv with Anaconda
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32

import pywintypes
pywintypes
<module 'pywintypes' (C:\ProgramData\Anaconda3\Library\bin\pywintypes37.dll)>
RESULT: No, pywintypes is not in the system python

4- Activate venv, then Install pywin32==225
C:\dev\python_visualizations [master +0 ~2 -0 !]>(venv) pip install pywin32==225 Collecting pywin32==225
Using cached https://files.pythonhosted.org/packages/b5/26/801bc6d99612977accac84b2d8ad06efa4a7d831c5e2813ca9baf700b646/pywin32-225-cp37-cp37m-win_amd64.whl
Installing collected packages: pywin32
Found existing installation: pywin32 224
Uninstalling pywin32-224:
Successfully uninstalled pywin32-224
Successfully installed pywin32-225

5- Check python path
C:\dev\python_visualizations [master +0 ~2 -0 !]>(venv) which python /c/dev/python_visualizations/venv/Scripts/python

6- Check path of pywintypes
C:\dev\python_visualizations [master +0 ~2 -0 !]>(venv) python Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32

import pywintypes
import inspect
inspect.getfile(pywintypes)
'C:\ProgramData\Anaconda3\Library\bin\pywintypes37.dll'
RESULT: Note wrong path, this should be using pywin32 installed in the virtualenv, not the system wide Anaconda environment

6- Run jupyter notebook, get kernel error
jupyter_pywin32==225_fails

pywin32==225_jupyter_error_traceback.txt.docx

RESULT: error due to wrong path for pywin32==225

@mhammond
Copy link
Owner

mhammond commented Oct 6, 2019

Under certain conditions, pywin32==225 causes jupyter notebooks to fail due to ImportError: DLL load failed: when users system is configured such that pywintypes is found under this path: C:\\ProgramData\\Anaconda3\\Library\\bin\\pywintypes37.dll.

Thanks very much for that info. This isn't a bug in pywin32-225 - pywin32 must use the pywintypesXX.dll that came with the running version, so this problem is going to keep happening forever. If the version in C:\\ProgramData\\Anaconda3\\Library\\bin\\pywintypes37.dll is updated with the one that came with pywin32-225, then pywin32-225 will again work - but the same problem is likely to then occur in 226, etc.

It appears pywin32 ships with Anaconda, and it has been installed in a non-standard way. You really need to talk to them to work out what the supported upgrade process is.

@MSeal
Copy link

MSeal commented Oct 8, 2019

I've opened an issue in the feedstock pointing to this thread so the relevant maintainer of that can hopefully take action to fix the root issue.

@Avasam
Copy link
Collaborator

Avasam commented Mar 17, 2024

Since 71afa71, the PATH is now prepended, rather than appended. For Python >= 3.8, the PATH environment variable isn't even used. This is included in pywin32==226.

Python 3.7 has also reached EOL (meaning no security fixes/support) and I'd recommend migrating over to 3.8+ (see #2207)

.exe installers are now deprecated #1939, so you should install from PyPI (ie: pip install pywin32>=226)

Given the sheer amount of "ImportError: DLL load failed: The specified module could not be found." issue duplication and old history, I'd like to consolidate the current state of these issues.

@JindiXu @surfaceowl Now your error is slightly different, but the history of this thread all happened before the above mentioned fixes. Can you confirm if it still happens with:

  • Python >=3.8
  • pywin32 >= 226
  • Installing from a wheel hosted on PyPI (pip install pywin32), NOT a .exe installer ?

If you still do, please also try https://github.com/mhammond/pywin32#troubleshooting and let us know if it did resolve your issue.

@Avasam Avasam changed the title Jupyter Notebook crash on pywin32==225 Jupyter Notebook crash with "ImportError: DLL load failed: The specified procedure could not be found" Mar 17, 2024
@surfaceowl
Copy link

@Avasam -- thanks for checking in from my review - confirming the fix was successful! I do not have the same issue anymore

Thanks to you and the team for all the work on this issue, and importantly the updated docs that clearly explain the root cause of the issue and lay out an installation path that avoids the dll conflict.

my results in screenshot below meets all conditions:

  1. using python in Windows (win 11)
  2. python >3.8 (example uses 3.12)
  3. pywin > 226 (pip only installs latest, currrently 306)
  4. installed from pypi wheel not .exe

pywin32_fix_confirmation 2024-03-18_11-20-20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants