Page 1 of 1

Cannot import module can.interfaces.pcan for CAN interface

Posted: Thu 17. Mar 2022, 14:58
by Clemlsn
Hello,

I developped a python script with the PCAN-Basic API, on my IDE when I launch the program on run or debug, I have no issue. Everything is working great.
I need to create a .exe to share the program. I used pyinstaller to create an .exe of the .py files, this part seems to process fine.

But when I open the exe file, I have the following error:
Image

I have the python-can API installed (4.0.0), I tried to copy the can folder at the root of my .exe file, but it didn't help. I feel like it's only a matter of linking this folder to the program but I didn't manage to solve it.

Have you already encounter this issue and know a way to solve it ?

Thanks,
Clément

Re: Cannot import module can.interfaces.pcan for CAN interface

Posted: Thu 17. Mar 2022, 16:53
by M.Maidhof
Hi,

please install the PCANBasic API through our driver setup, and delete all local PCANBasic dlls from the exe directory and try again.

regards

Michael

Re: Cannot import module can.interfaces.pcan for CAN interface

Posted: Fri 18. Mar 2022, 10:44
by Clemlsn
Hi,

I already have the Pcan usb driver installed, I tried to copy the latest PCANBasic.dll files according to the readme file:
Windows 64-bit systems:
32-bit DLL > Windows\SysWOW64
64-bit DLL > Windows\System32

But then I got an error when I build the program:
OSError: [WinError 193] %1 is not a valid Win32 application

so I reinstalled the Pcan usb driver, and this issue disappeared.

In my project folder I removed all useless files and the PCAN dll files, the debug is still working fine, I generate the exe file, there is nothing else but the .exe file in the folder but I still have the same error message

Re: Cannot import module can.interfaces.pcan for CAN interface

Posted: Fri 18. Mar 2022, 12:03
by M.Maidhof
Hi,

please test with the examples from the following link on your system:

32bit App: https://www.peak-system.com/produktcd/D ... xample.exe

64bit App: https://www.peak-system.com/produktcd/D ... xample.exe

If both will work on your system, the problem is based on your python application and not on our APIs/DLL or drivers.

regards

Michael

Re: Cannot import module can.interfaces.pcan for CAN interface

Posted: Fri 18. Mar 2022, 16:13
by Clemlsn
Ok I figured it out, it's due to pyinstaller.
PyInstaller specifically installs the dependencies at the top of the main file you want to execute. Dependencies in other python files that you import into the main file aren't detected by PyInstaller.
So I added "import can.interfaces.pcan" in my file and now the final exe is working.
I think it could work as well if the link is added in the hiddenimports in the .spec

Re: Cannot import module can.interfaces.pcan for CAN interface

Posted: Fri 18. Mar 2022, 16:30
by M.Maidhof
Thanks for the feedback

regards

Michael