Python fails to “from pcan.PCANBasic import *”

The free CAN Software API (Application Programming Interface) for Windows®
Locked
jjollota
Posts: 5
Joined: Mon 20. Jan 2025, 19:48

Python fails to “from pcan.PCANBasic import *”

Post by jjollota » Tue 21. Jan 2025, 16:46

I have seen a number of posts about this topic, and I believe I have tried everything that was suggested, but I cannot get this pcan.PCANBasic import to work.

I have tried:
• Installed latest PEAK-System_Driver-Setup
• Verified 64bit DLL in System32 and 32bit in SysWow64
• Tried copying each PCANBasic.DLL to local directory.

Should there be an explicit PATH statement with “pcan” in it?
Any other steps to isolate the problem?

Thanks,
Jim

M.Heidemann
Sales & Support
Sales & Support
Posts: 1060
Joined: Fri 20. Sep 2019, 13:31

Re: Python fails to “from pcan.PCANBasic import *”

Post by M.Heidemann » Wed 22. Jan 2025, 08:56

Hello,

Is the header file "PcanBasic.py" present?

BR

Marvin
---
Marvin Heidemann
PEAK-Support Team

jjollota
Posts: 5
Joined: Mon 20. Jan 2025, 19:48

Re: Python fails to “from pcan.PCANBasic import *”

Post by jjollota » Thu 23. Jan 2025, 19:00

Yes, I have everything in one directory, including the PCANBasic.py.

Jim

M.Heidemann
Sales & Support
Sales & Support
Posts: 1060
Joined: Fri 20. Sep 2019, 13:31

Re: Python fails to “from pcan.PCANBasic import *”

Post by M.Heidemann » Fri 24. Jan 2025, 11:35

Hello,

Can you share part of your code, especially the imports?
---
Marvin Heidemann
PEAK-Support Team

jjollota
Posts: 5
Joined: Mon 20. Jan 2025, 19:48

Re: Python fails to “from pcan.PCANBasic import *”

Post by jjollota » Fri 24. Jan 2025, 17:38

Yes, it is the start of the python file:

Code: Select all

try:
    from tqdm import tqdm
    from pcan.PCANBasic import *
    import ctypes
except ImportError:
    print('[ERROR] Dependant modules not available of PCANBasic.')
    print('')
    sys.exit()
And it fails on the pcan.PCANBasic import line
Last edited by K.Wagner on Tue 28. Jan 2025, 10:59, edited 1 time in total.
Reason: Code formatted for better reading

K.Wagner
Software Development
Software Development
Posts: 1066
Joined: Wed 22. Sep 2010, 13:36

Re: Python fails to “from pcan.PCANBasic import *”

Post by K.Wagner » Mon 27. Jan 2025, 11:35

Hello,

if you have the drivers and PCAN-Basic installed (PEAK-Drivers Setup), and also Python, then you should be able to load and use the library. It could be a problem with environment configuration in Pyhton itself. Which Python version are you using? which OS are you using?

In normal cases, you should be able:
  • to compile and launch the Pyhton samples contained in the PCAN-Basic package (console and GUI. The last one uses tkinter).
    Pyhton2.png
    Pyhton2.png (113.58 KiB) Viewed 1091 times
  • to load the PCANBasic.py module with Python IDLE and run it. Over the console then directly call the API functions.
    Python.png
    Python.png (51.31 KiB) Viewed 1091 times
Please try downloading the PCAN-Basic package (if you do not have it), and give the sample projects a try.
Best regards,
Keneth

jjollota
Posts: 5
Joined: Mon 20. Jan 2025, 19:48

Re: Python fails to “from pcan.PCANBasic import *”

Post by jjollota » Mon 27. Jan 2025, 19:36

Keneth,
Thank you for your help on this. I am not a Python-guy, but your examples were key. Your examples imported the library via "from PCANBasic import *", but the example code I got from the microprocessor company was "from pcan.PCANBasic import *". I don't know the ramifications of the difference, but your line does not exception.
Thanks,
Jim

K.Wagner
Software Development
Software Development
Posts: 1066
Joined: Wed 22. Sep 2010, 13:36

Re: Python fails to “from pcan.PCANBasic import *”

Post by K.Wagner » Tue 28. Jan 2025, 10:58

Hello,

OK. I missed the incorrect import in your code.
Thanks for the feedback.

Closed.
Best regards,
Keneth

Locked