Skip to content

pyi_rth_pkgutil.py hook might not work under MacOS in onefile mode #6537

@k9ert

Description

@k9ert

Description of the issue

I'm using iter_modules in our cross-platform OpenSource Project Specter-Desktop (spec-file).

For that, the pyi_rth_pkgutil.py-hook is quite useful and solved my issue on the linux-platform. However, i have an issue with the MacOS-build at runtime:

$  ./dist/specterd server --config=DevelopmentConfig
Initializing HWI...
[2022-01-24 11:49:07,827] INFO in server: Configuration: cryptoadvance.specter.config.DevelopmentConfig
[2022-01-24 11:49:07,828] INFO in specter_migrator: Initiated MigDataManager(/Users/thomasmuller/.specter_dev/migration_data.json events:3 execs:2 )
Traceback (most recent call last):
  File "specterd.py", line 4, in <module>
    entry_point()
  File "click/core.py", line 829, in __call__
  File "click/core.py", line 782, in main
  File "click/core.py", line 1259, in invoke
  File "click/core.py", line 1066, in invoke
  File "click/core.py", line 610, in invoke
  File "cryptoadvance/specter/cli/cli_server.py", line 114, in server
  File "cryptoadvance/specter/server.py", line 104, in init_app
  File "cryptoadvance/specter/util/specter_migrator.py", line 125, in execute_migrations
  File "cryptoadvance/specter/util/specter_migrator.py", line 107, in plan_migration
  File "cryptoadvance/specter/util/specter_migrator.py", line 161, in get_migration_classes
  File "PyInstaller/hooks/rthooks/pyi_rth_pkgutil.py", line 59, in _pyi_pkgutil_iter_modules
AssertionError
[20771] Failed to execute script 'specterd' due to unhandled exception!
(.env) thomasmuller @ Thomass-Air.fritz.box ➜  pyinstaller git:(service_swan) ✗

So the relevant code is this:

        SYS_PREFIX = sys._MEIPASS + os.path.sep
        SYS_PREFIXLEN = len(SYS_PREFIX)
        # Only single path is supported, and it must start with sys._MEIPASS.
        pkg_path = os.path.normpath(path[0])
        assert pkg_path.startswith(SYS_PREFIX)

So i inserted some debugging code and figured out that:

SYS_PREFIX: /var/folders/bd/k__jfmz112sb1_dyz4rxwfzh0000gn/T/
pkg_path: /private/var/folders/bd/k__jfmz112sb1_dyz4rxwfzh0000gn/T/_MEIBqFxGW/cryptoadvance/specter/util/migrations

So in combination with the comment above, it seems that MacOS is using "multiple path" and so MacOS is not supported here?
On the other hand, this link is claiming that private/var is only a symlink to /var. So i added this and this seem to have solved it?

        if pkg_path.startswith("/private"):
                pkg_path = pkg_path[8:]
        assert pkg_path.startswith(SYS_PREFIX)

Is this a valid fix? I might make a PR if someone can give me some guidance on this.

Context information (for bug reports)

  • Output of pyinstaller --version: 4.8
  • Version of Python:
  • Platform: OS X
  • How you installed Python: brew
  • Did you also try this on another platform? Does it work there? --> Yes, works on Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions