nucleic / kiwi

Efficient C++ implementation of the Cassowary constraint solving algorithm
https://kiwisolver.readthedocs.io/en/latest/
Other
692 stars 88 forks source link

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 closed 4 months ago

edoardo-kolver commented 5 months ago

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 commented 5 months ago

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: