Skip to content
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

Imports in autogenerated files wrong? #23

Open
stephan192 opened this issue Feb 14, 2024 · 3 comments
Open

Imports in autogenerated files wrong? #23

stephan192 opened this issue Feb 14, 2024 · 3 comments

Comments

@stephan192
Copy link

I have a working python script which uses your pya2l module. As long as i run my script from VisualStudioCode or CMD everything is working.
But when i'm trying to generate an exe file out of my python script via PyInstaller or Nuitka, in both cases the generated exe file is not running and in the console i get the following error message. The following message is reported by the exe generated with PyInstaller. The error message from the one generated with Nuitka is, besides the filepaths, identical.

Traceback (most recent call last):
  File "my_script.py", line 17, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "my_lib.py", line 5, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "my_a2l_parser.py", line 5, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pya2l\__init__.py", line 12, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pya2l\cli.py", line 18, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pya2l\parser.py", line 15, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pya2l\protobuf\API_pb2.py", line 15, in <module>
ModuleNotFoundError: No module named 'protobuf'
[10064] Failed to execute script 'my_script' due to unhandled exception!

Used versions (All packages installed via pip):
Python: 3.11.1
pya2l 0.1.2
Nuitka 2.0.1
pyinstaller 6.3.0

Looking into one of the autogenerated files, e.g. protobuf\API_pb2.py, Pylance installed with VisualStudioCode reports reportMissingImports for line 15. This fits to the error message shown above.

If i change all similar includes in all autogenerated files from e.g.
from protobuf import A2L_pb2 as protobuf_dot_A2L__pb2
to
from . import A2L_pb2 as protobuf_dot_A2L__pb2
i can generate working exe files with both PyInstaller and Nuitka and the Pylance warning vanishes.

For me it seems as if the script which generates the content of the protobuf folder makes an error.

Additional note:
When using PyInstaller and Nuitka you have to explicitly add a2l_grpc_windows_amd64.dll to get a working exe file. But this is not related to this issue.

@bertbroer
Copy link

I run into the same issue. Have you found a workaround?

@Sauci
Copy link
Owner

Sauci commented Mar 20, 2024

It seems to be a known bug/limitation, which is apparently not close from beeing fixed.
In the meanwhile, this tool has been developed to overcome this problem. Could you give it a try and give a feedback if it actually fixes the integration problem with PyInstaller?
Thanks

@stephan192
Copy link
Author

I adjusted every relevant import from from protobuf to from . to get it working.

But finally i decided to write my one, very reduced, A2L parser instead of using py2al because i don't want to use libraries which have to be adjusted after installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants