4

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?

CrazyChucky
  • 3,263
  • 4
  • 11
  • 25
Nandu
  • 53
  • 2
  • 5

4 Answers4

2

I was having this issue today while using python-can 3.3.3, and resolved it by updating to 3.3.4 which was released not that long ago.

Since the package is still being worked on, it looks like they accidentally released a broken version with 3.3.3.

2

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.

0

In case that issue happens with pyinstaller 4.0 after the .py packed as .exe, add below line to the code;

import can.interfaces.vector
M.Emin
  • 63
  • 7
0

I accidentally did a pip install can instead of pip install python-can, which led me to this error too. Remove the can package and try again with python-can.