简体   繁体   中英

ModuleNotFoundError and ImportError when trying to import can package

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)

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

I think you can try following command first:

`pip install python3-can`

Afterward, I could implement the libs you needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM