Repository: pyinstaller/pyinstaller

Issue:
about inspect.py error
I have checked many previous answers, but there is still no solution. Looking forward to your reply
![A`@C_HWQ$1F`$Z_(9J1)8B](https://user-images.githubusercontent.com/48466610/134448962-50acd103-589a-49d0-8094-4fb8b91683e1.png)




Discussion:
You need to ensure that source .py files of whatever torch-based library you are using (`kornia`?) are collected.

Try adding a `--collect-all kornia` to your PyInstaller command, or use `PyInstaller.utils.hooks.collect_data_files('kornia', py_files=True)` in your spec file (or a custom hook for `kornia`).
And once you have those .py files collected, you will hit a bug where we don't handle packages' `__init__.py` files correctly in our loader:
https://github.com/pyinstaller/pyinstaller/blob/5a02f55c696f16b98f23a8b487f3daa8f644a8d2/PyInstaller/loader/pyimod03_importers.py#L336-L340

If you're in a hurry, you can try patching those lines in your local pyinstaller installation, so they read:
```python
        if fullname in self.toc:
            # Try loading .py file from the filesystem
            if self.is_package(fullname):
                fullname += '.__init__'
            filename = pyi_os_path.os_path_join(
                SYS_PREFIX,
                fullname.replace('.', pyi_os_path.os_sep) + '.py')
```

A simple test program,
```python
# program.py
import kornia
print("Hello")
```
frozen with `pyinstaller --clean --noconfirm --collect-all kornia program.py` should work afterwards.
> --collect-all kornia



> And once you have those .py files collected, you will hit a bug where we don't handle packages' `__init__.py` files correctly in our loader:
> https://github.com/pyinstaller/pyinstaller/blob/5a02f55c696f16b98f23a8b487f3daa8f644a8d2/PyInstaller/loader/pyimod03_importers.py#L336-L340
> 
> If you're in a hurry, you can try patching those lines in your local pyinstaller installation, so they read:
> 
> ```python
>         if fullname in self.toc:
>             # Try loading .py file from the filesystem
>             if self.is_package(fullname):
>                 fullname += '.__init__'
>             filename = pyi_os_path.os_path_join(
>                 SYS_PREFIX,
>                 fullname.replace('.', pyi_os_path.os_sep) + '.py')
> ```
> 
> A simple test program,
> 
> ```python
> # program.py
> import kornia
> print("Hello")
> ```
> 
> frozen with `pyinstaller --clean --noconfirm --collect-all kornia program.py` should work afterwards.

Yes, he has started to work. Thank you for your reply. Hope you have a wonderful day

Resolving patch:
diff --git a/PyInstaller/loader/pyimod03_importers.py b/PyInstaller/loader/pyimod03_importers.py
--- a/PyInstaller/loader/pyimod03_importers.py
+++ b/PyInstaller/loader/pyimod03_importers.py
@@ -308,6 +308,8 @@ def get_source(self, fullname):
         """
         if fullname in self.toc:
             # Try loading the .py file from the filesystem (only for collected modules)
+            if self.is_package(fullname):
+                fullname += '.__init__'
             filename = pyi_os_path.os_path_join(SYS_PREFIX, fullname.replace('.', pyi_os_path.os_sep) + '.py')
             try:
                 # Read in binary mode, then decode


Test patch: