-1

I have written a python script, using eel for the GUI, that converts & does some calculations on files in a folder. For this, i am using a python library called asammdf. The code works well in an IDE but when i use pyinstallerand create a .exe file the code doesn't seem to work the same way.

import eel
from pathlib import Path
from asammdf import MDF
from pathlib import Path
import glob
import sys
import os
from datetime import timedelta


eel.init("path\to\folder\Python")
def python_code():
    # a python script that uses asammdf

@eel.expose

I have tried copying the asammdf directory into the python folder and pyinstaller seems to include it in the .exe dist folder but still it doesn't work. Can anyone help me out please?

The error message comes as --

asammdf\mdf.py:4597: UserWarning: The argument `ignore_invalid_signals` from the method `extract_bus_logging` is no longer used and will be removed in the future
Traceback (most recent call last):
  File "eel\__init__.py", line 281, in _process_message
  File "converterrxd_csv.py", line 79, in pythoncode
  File "asammdf\mdf.py", line 4625, in extract_bus_logging
  File "asammdf\mdf.py", line 4666, in _extract_can_logging
  File "asammdf\blocks\utils.py", line 1807, in load_can_database
  File "canmatrix\formats\__init__.py", line 71, in loadp
  File "canmatrix\formats\__init__.py", line 86, in load
KeyError: 'canmatrix.formats.dbc'

I tried installing the can-matrix package as well but that doesn't solve the problem.

rioV8
  • 24,506
  • 3
  • 32
  • 49
Suprava
  • 69
  • 6
  • What are you typing in the terminal when you use pyinstaler - i.e., are you using onefile? Do you have all the correct hook files in the pyinstaler folder - e.g., `hook-asammdf.py`? Are you getting any errors or warnings when running pyinstaller? – It_is_Chris Feb 06 '23 at 14:12
  • i typed this `pyinstaller .py --hidden-import asammdf` . No the installation & .exe creation did not give any error. @It_is_Chris – Suprava Feb 06 '23 at 14:19
  • Go into the pyinstaller hook folder and make sure all the packages you are using have a hook file. If not, you will probably need to create a hook file for the ones missing. – It_is_Chris Feb 06 '23 at 14:21
  • @it_is_Chris I did use hooks to import the `asammdf` library but the error still persists. The Key error is shown as `canmatrix.formats.dbc` but i havent used that in my code. I tried putting that in the hooks file but still the error message doesn't change. Do you know what could be the issue? – Suprava Feb 07 '23 at 05:36
  • I found a solution. That is to manually copy the can-matrix folder to the dist folder after the '.exe' file is made. 'Pyinstaller' is somehow not including the complete can-matrix package to the dist folder. This works for now, but what if i want to create a single '.exe' file? In that case, manually copying the packages would not work. What are your thoughts? – Suprava Feb 07 '23 at 06:34
  • using onefile is they way to go so try doing `pyinstaller some_pyhon_file.py -F` – It_is_Chris Feb 07 '23 at 12:57

1 Answers1

1

You need to add the hidden import for canmatrix

see https://github.com/danielhrisca/asammdf/blob/180a1588737ae7aaf367aaa8fd1c81aff616df16/asammdf.spec#L37

danielhrisca
  • 665
  • 1
  • 5
  • 11