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

On Windows 10 LTSC, import kiwisolver (and/or import matplotlib) fails with DLL _cext even after installing VS runtime (solution incl) #178

Closed
edoardo-kolver opened this issue Jun 13, 2024 · 1 comment · Fixed by #179

Comments

@edoardo-kolver
Copy link

Crosspost from matplotlib. Not sure who's at fault here. The DLL is not missing, it just has a hash in the filename for some reason, that kiwisolver cannot find.
Installing the VS runtime does NOT solve this problem. Making a copy of the DLL with the fixed filename (without the hash) solves the problem.

importing matplotlib 3.9.0 (with kiwisolver 1.4.5 and also tested with kiwisolver 1.3.1) on windows 10 gives this error:
(importing kiwisolver alone has the same issue):

Python 3.11.9 (tags/v3.11.9:de54cf5, Apr  2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\py\Lib\site-packages\matplotlib\__init__.py", line 276, in <module>
    _check_versions()
  File "c:\py\Lib\site-packages\matplotlib\__init__.py", line 270, in _check_versions
    module = importlib.import_module(modname)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\py\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\py\Lib\site-packages\kiwisolver\__init__.py", line 8, in <module>
    from ._cext import (
ImportError: DLL load failed while importing _cext: The specified module could not be found.

Installing the visual studio redistributable runtime does NOT solve this issue.

However, in my site-packages/matplotlib.libs directory, I have this file:
msvcp140-(here some sort of long garbage hash).dll
If I make a copy of this file in the same directory, renaming it msvcp140.dll (so that I have both files, one with the hash and one without), then importing matplotlib works and so does importing kiwisolver.

This only happens on Windows 10.
On Windows 11, it seems to find the DLL somehow.
But the DLL is already there. Kiwisolver just needs to be able to locate it with the hash in the name. I don't know why there is a hash in the name, but matplotlib needs it (if you just rename the DLL, matplotlib fails, you need both named versions)

@ksunden
Copy link
Contributor

ksunden commented Jun 17, 2024

You may wish to consider running delvewheel during the release process for kiwisolver. This is what bundles the msvc runtime for Matplotlib (and adds a hash to avoid problems that can potentially occur because of the innards of python loading dlls... namely clobbering potentially incompatible versions loaded by different python modules... here is the discussion from delvewheel's readme as to why they do name mangling by default)

Here is the CIBW docs about it, note it is not used by default on windows, though similar tools are used on mac/linux builds by default by CIBW:

Here is the lines which enable it in Matplotlib:

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

Successfully merging a pull request may close this issue.

2 participants