Home > Mobile >  ModuleNotFoundError and ImportError when trying to import can package
ModuleNotFoundError and ImportError when trying to import can package

Time:08-21

When I try to run code with imported can package

import can 
from can.interfaces.vector import canlib
from datetime import datetime

I get an error:

ModuleNotFoundError: No module named 'can.interfaces'; 'can' is not a package. 

My interpreter path is global 1 and packages are installed in the C:\Python\Python310\Lib\site-packages. What might cause the problem? I'm using Windows 10.

EDIT

I changed file name from can.py to other and it works (thanks FlyingTeller), but now I get another error when trying to import can module.

Traceback (most recent call last):
  File "c:\__work__\DownloadFiles_Karol\nweasdawd.py", line 2, in <module>
    from can.interfaces.vector import canlib
  File "C:\Python\Python310\lib\site-packages\can\interfaces\vector\__init__.py", line 4, in <module>
    from .canlib import VectorBus, VectorChannelConfig
  File "C:\Python\Python310\lib\site-packages\can\interfaces\vector\canlib.py", line 39, in <module>
    from can import BusABC, Message, CanInterfaceNotImplementedError, CanInitializationError
ImportError: cannot import name 'BusABC' from 'can' (C:\Python\Python310\lib\site-packages\can\__init__.py)

CodePudding user response:

You have named your file can, so it is shadowing the import that you want. Rename it to something else

CodePudding user response:

I think you can try following command first :

`pip install python3-can`

Afterward, I could implement the libs you needed.

  • Related