I have some code to try to detect if an IXXAT USB-to-CAN device is connected. It works when I run it in python, but I need to build it into an executable. I built the executable using the command, python -m PyInstaller --onefile ixxatExample.py. However, the executable does not work, and it keeps telling me there is no IXXAT devices connected. But if I run it in python, then it will list me the IXXATs connected.
The library I am using is python-can and I import it in with “import can” and the line I use to find the IXXAT device is:
ixxat_configs = can.detect_available_configs("ixxat")
I wonder if there is a exception that is being hidden.
At any point in your code do you trap exceptions?
Are you always logging when expections happen?
Yes, I tried catching any exceptions with the code below. Is there another way I should go about it?
try:
ixxat_configs = can.detect_available_configs("ixxat")
except Exception as e:
print(e)
While you are debugging this issue I would remove the try/except so that you can see full tracebacks.
Also add debug logs so that you are sure the code is running as you expect. Does it try to run that key line at all for example?
I figured out the solution to the problem. So, when using PyInstaller to create an executable, all libraries need to be declared in the main.py python script.
In the case of python-can, you have to explicitly say the interfaces you want to include. The same issue was had by someone here: https://stackoverflow.com/questions/51312059/kvasers-can-library-has-been-loaded-but-program-executable-outputs-a-no-modul. So, for me to find the IXXAT devices connected, I needed to do:
import can.interfaces.ixxat
1 Like