Showing ImportError: cannot import name 'Message' from 'can'

1.1k Views Asked by At

I am importing CAN messages in Python and I am using python-can library. So the line in my python code here is:

from can import Message

It was working fine but after I changed the folders, I am getting the below error:

Traceback (most recent call last):
  File "/home/rafi/PycharmProjects/Right Turn/CAN_simulator_Recv.py", line 12, in <module>
    from can import Message
ImportError: cannot import name 'Message' from 'can' (/home/rafi/.local/lib/python3.8/site-packages/can/__init__.py)

Can anyone help me with this error? Maybe it has something to do with directory or packages? The same can library is working fine in other linux machines. I tried uninstalling python-can but it doesn't work. Please help.

1

There are 1 best solutions below

0
On

It's some kind of import bug. Try import Message like this:

from can.message import Message 

Everything worked for me.