adang1345 / delvewheel

Self-contained Python wheels for Windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The __init__.py file makes our wheel unusable

ssaue opened this issue · comments

After an upgrade of delvewheel around October 15 we get consistent errors when importing the wheel "repaired" with delvewheel. The wheel installs successfully and we are able to import its single module "my_module". However, if we try to access the module in any way, we get the error:

AttributeError: module 'my_module' has no attribute 'my_attribute'

The only difference before and after the upgrade is that delvewheel adds an init.py file in a subfolder. If we manually remove that file from the wheel it works perfectly again.

Is there a way to avoid this added init.py file?

The purpose of adding __init__.py is so that the location of the dependent DLLs is added to the DLL search path. Normally, without this file, module imports may fail. I'll need more information to figure out why __init__.py is causing issues for you.

Did things work for you with an older version of delvewheel? If so, was __init__.py added with this older version and do you remember what the older version of delvewheel was?

Can I see the wheel where this issue is happening? You can provide a GitHub link if the wheel is stored on GitHub, or you can upload the file in a comment. Also, if an older version of delvewheel worked for you, can I see the functional wheel that was created by the older version?

Sorry for responding this late. I'm afraid I can't share our wheels publicly. I can only show the file structure inside the wheel:

Top level:
image

Inside the "nucleus" subfolder ("hardware" and "ml-models" contain config data used by the application):
image

We started using delvewheel in February 2021 and we probably used that initial version until my upgrade in October. We had no problems with the older version. It did not add the __init.py__ file. Hence the quick fix with the latest version is simply to remove that file from the "nucleus" subfolder.

I am not leaving you with much to work on, I'm afraid. But it would be great to avoid the manual removal from the wheels.

Thanks, this is enough information for me to determine what the problem is. The issue is related to the fact that you have a folder and a module with the same name, nucleus. When you do import nucleus, Python must choose whether you mean the folder nucleus or the module nucleus.cp37-win_amd64.pyd. When the file __init__.py does not exist in the folder, Python chooses the module, which is what you expect. When __init__.py exists in the folder, Python chooses the folder, which is causing problems.

The solution would be for delvewheel to avoid adding the file __init__.py into a folder if it is next to a module with the same name. I'll get started on implementing this.

Thanks! That makes a lot of sense. I really look forward to a solution for this

Thanks a lot for doing this! Your fix did the trick