Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError when using python-can (module 'can' has no attribute 'interface')

Tags:

python

can-bus

I'm getting an error when running the following code:

import can #importing CAN module
import time

bus1 = can.interface.Bus(bustype='vector', channel=0, bitrate=500000,
                         app_name='python-can')
bus2 = can.interface.Bus(bustype='vector', channel=1, bitrate=500000,
                         app_name='python-can')

msg1 = can.Message(arbitration_id = 0xa1,
                   data = [1, 2, 3, 4, 5, 6, 7, 8],
                   extended_id = False)
msg2 = can.Message(arbitration_id = 0xa3,
                   data = [8, 7, 6, 5, 4, 3, 2, 1],
                   extended_id = False)
bus1.send(msg1)
time.sleep(1.0)
bus2.send(msg2)
bus1.shutdown()
bus2.shutdown()

I can import the CAN module, but then I get this error:

AttributeError: module 'can' has no attribute 'interface'

I am trying to send dummy messages to virtual CAN. How can I fix this error?

like image 988
Nandu Avatar asked Oct 25 '25 02:10

Nandu


1 Answers

I made a silly mistake and had a file called:

can.py

in the same folder! I was obviously importing the wrong file, so renaming this file fixed my problem.

like image 122
benjamin deworsop Avatar answered Oct 27 '25 15:10

benjamin deworsop



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!