New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkgutil.iter_modules is broken on MacOS #7884
Comments
That bug report I just linked is another project that doesn't use FBS so I don't think it effects it. |
Are you adding your packages as data files then? Your package shouldn't be there at all -- it should be embedded inside the executable. |
The actual code is embedded in the executable but the The import mechanism may still be resolving them via |
I have just put together a minimal test example to debug this behaviour. Your The symbolic links in I will update the original post |
Description of the issue
I am trying to build an application on MacOS that uses pkguilt.iter_modules to dynamically find and load modules however it is not finding any modules.
The modules are there and can be imported with importlib.import_module.
Note that I am using PyInstaller with FBS but I don't believe the latter changes anything that would effect this.
The following is an example project structure
Here is the code that does not work
The last line prints an empty list when built with PyInstaller.
I have done a bit of a dive into the code and I believe this is a rather complex mixup with paths and symbolic links.
https://github.com/pyinstaller/pyinstaller/blob/develop/PyInstaller/hooks/rthooks/pyi_rth_pkgutil.py
It looks like #6539 had a go at supporting symbolic links but it only resolves symbolic links up to the
_MEIPASS
directory.On MacOS
_MEIPASS
is equal to"/path/to/my_package.app/Contents/MacOS/"
my_package.__path__
is equal to["/path/to/my_package.app/Contents/MacOS/my_package"]
/path/to/my_package.app/Contents/MacOS/my_package
is a symbolic link to/path/to/my_package.app/Contents/Resources/my_package
when there are data files present in that package.The
iter_modules
hook expands symbolic links in thepath
variable which converts"/path/to/my_package.app/Contents/MacOS/my_package"
to"/path/to/my_package.app/Contents/Resources/my_package"
The following code then skips over the directory because it does not start with
SYS_PREFIX
I don't know how this should be implemented but we need to resolve the expected path relative to the
_MEIPASS
directory and then expand symbolic links and only then skip if the package path does not start with the directory.Context information (for bug reports)
pyinstaller --version
:5.13.0
The text was updated successfully, but these errors were encountered: