Importing installed wheel fails with "ImportError: DLL load failed while importing"
bauerj opened this issue · comments
Hey,
first of all, thanks for creating this library! I've long been missing auditwheel on Windows.
I just tested it with pdftotext. delvewheel repair
seems to have worked as I can see useful DLL files in pdftotext.libs. However, when I try to import it I get
PS C:\Users\bauerj> py
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdftotext
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing pdftotext: Das angegebene Modul wurde nicht gefunden.
Is there any way to debug this and see which module couldn't be found? I've already used https://github.com/lucasg/Dependencies on the .pyd file but it seemed to resolve all libraries just fine.
This is on Windows 10 by the way and as far as I can see no LoadLibrary
is used.
If you want to look into this, the wheels can be found here: https://dev.azure.com/jhnnbr/pdftotext/_build/results?buildId=19&view=artifacts&pathAsName=false&type=publishedArtifacts
I see what the problem is. The current strategy is that delvewheel
creates or edits __init__.py
in every top-level package so that the DLLs can be found at runtime. You have a top-level module (e.g. pdftotext.cp39-win_amd64.pyd
) that is not in any package, which is a case I had not considered. In this situation, there's no place to put an __init__.py
.
Here's my plan for fixing this. If a top-level extension module is found in the wheel, dependent DLLs are copied into the {distribution}-{version}.data/platlib
directory inside the wheel. When the wheel is installed, these DLLs will then be placed into the same directory as the top-level module and thus will be found when the module is imported.
I see. That sounds like a good idea. Can I test that by just renaming the directory in the wheel?
You can test by creating the folder pdftotext-2.1.5.data/platlib
in the wheel, moving the contents of pdftotext.libs
into pdftotext-2.1.5.data/platlib
, and deleting pdftotext.libs
.
Thank you, that works flawlessly.