{"action":"created","issue":{"url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/2147","repository_url":"https://api.github.com/repos/pyinstaller/pyinstaller","labels_url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/2147/labels{/name}","comments_url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/2147/comments","events_url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/2147/events","html_url":"https://github.com/pyinstaller/pyinstaller/issues/2147","id":171539456,"number":2147,"title":"hook-zmq no longer works for PyZMQ 15.4.0+","user":{"login":"codewarrior0","id":307683,"avatar_url":"https://avatars.githubusercontent.com/u/307683?v=3","gravatar_id":"","url":"https://api.github.com/users/codewarrior0","html_url":"https://github.com/codewarrior0","followers_url":"https://api.github.com/users/codewarrior0/followers","following_url":"https://api.github.com/users/codewarrior0/following{/other_user}","gists_url":"https://api.github.com/users/codewarrior0/gists{/gist_id}","starred_url":"https://api.github.com/users/codewarrior0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codewarrior0/subscriptions","organizations_url":"https://api.github.com/users/codewarrior0/orgs","repos_url":"https://api.github.com/users/codewarrior0/repos","events_url":"https://api.github.com/users/codewarrior0/events{/privacy}","received_events_url":"https://api.github.com/users/codewarrior0/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pyinstaller/pyinstaller/labels/@medium","name":"@medium","color":"FFD07D"},{"url":"https://api.github.com/repos/pyinstaller/pyinstaller/labels/hooks","name":"hooks","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-08-16T23:12:34Z","updated_at":"2016-08-20T01:13:12Z","closed_at":null,"body":"Previously, `zmq.__init__` would search its package path for the library `libzmq.pyd` using a glob-pattern and then load it using a call to `ctypes.CDLL.LoadLibrary`. This allowed us to freeze the file as `zmq/libzmq.pyd` and also exclude the file `zmq.libzmq.pyd` (for reasons I will get into).\r\n\r\nAs of a recent update, `zmq.__init__` now simply imports the library as a Python module using `from . import libzmq`. When frozen, this import now silently fails, but leads to a different error. When PyZMQ later imports the extension modules under `zmq.backends`, it yields an error \"ImportError: DLL load failed: The specified module could not be find\". Since the backend modules are actually present, this indicates they failed to load because one of their DLL dependencies was not found - this dependency being `libzmq.pyd`.\r\n\r\n`libzmq.pyd` is not on the DLL search path. In the previous PyZMQ version, loading the DLL via `LoadLibrary` implicitly puts it on the search path as an already-loaded-DLL, so when the backends are imported, they can always find it. In the current version, it will only attempt to load this DLL through a Python import statement, which will cause our CExtensionImporter to try to load `zmq.libzmq.pyd`, and fail because it was excluded during the build process.\r\n\r\nIf `zmq.libzmq.pyd` is not excluded, we still get the same \"ImportError: DLL load failed\" while importing the backend modules: they link to the library by name, which is `libzmq.pyd`. Our CExtensionImporter will not import the module from `zmq/libzmq.pyd`. \r\n\r\nAs mentioned in another issue (https://github.com/pyinstaller/pyinstaller/issues/2005#issuecomment-222660537), I discovered that adding our importer to `sys.path_hooks` prevents the Python import system from falling back to the filesystem for imports: After the `sys.meta_path` importers fail to import `zmq.libzmq`, Python finds a cached `path_hooks` importer for the module `zmq` and stops there.\r\n\r\nThe resolution to this might be to change the importer added to `sys.path_hooks` to also search the filesystem if it fails to find the module in the archive.\r\n\r\n--\r\n\r\nThis issue may be specific to Windows and/or to PyZMQ installations that bundle libzmq (as opposed to allowing the system's package manager to install it)."},"comment":{"url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/comments/241169051","html_url":"https://github.com/pyinstaller/pyinstaller/issues/2147#issuecomment-241169051","issue_url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/2147","id":241169051,"user":{"login":"codewarrior0","id":307683,"avatar_url":"https://avatars.githubusercontent.com/u/307683?v=3","gravatar_id":"","url":"https://api.github.com/users/codewarrior0","html_url":"https://github.com/codewarrior0","followers_url":"https://api.github.com/users/codewarrior0/followers","following_url":"https://api.github.com/users/codewarrior0/following{/other_user}","gists_url":"https://api.github.com/users/codewarrior0/gists{/gist_id}","starred_url":"https://api.github.com/users/codewarrior0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codewarrior0/subscriptions","organizations_url":"https://api.github.com/users/codewarrior0/orgs","repos_url":"https://api.github.com/users/codewarrior0/repos","events_url":"https://api.github.com/users/codewarrior0/events{/privacy}","received_events_url":"https://api.github.com/users/codewarrior0/received_events","type":"User","site_admin":false},"created_at":"2016-08-20T01:13:12Z","updated_at":"2016-08-20T01:13:12Z","body":"> What if we did away with the CExtensionImporter, placing all extensions in a directory rather than a dotted filename (i.e. zmq/libzmq.dll instead of zmq.libzmq.dll?\r\n\r\nHmm. We might run afoul of the `sys.path_hooks` behavior that prevents the filesystem from being searched if a `path_hooks`-returned importer claims that pathname. Other than that, I get the feeling that CExtensionImporter (and the dotted filename pattern) is a legacy of the `iu.py` import hooking mechanism from the earliest versions of PyInstaller. I'd have to double check to be sure."}}
{"actor":{"display_login":"codewarrior0"}}