cannot import name ‘Message‘ from ‘can‘

1:python执行时候,报错没有 “message”指令;

PS E:\share\top_hqt409\hq_app\automation\auto_log\src> python .\remote.py
2022-11-12 13:48:25.489 | INFO     | hqobos:<module>:98 - load config file,total count:820
Traceback (most recent call last):
  File ".\remote-client.py", line 13, in <module>
    from can import Message
ImportError: cannot import name 'Message' from 'can' (C:\Users\Pi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\can\__init__.py)

2:查看 CAN模块下已有指令

>>> import can
>>> dir(can) 			# 查看CAN模块已安装指令
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
>>> can.__path__        # 查看 CAN模块安装路径
['C:\\Users\\Pi\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages\\can']
>>> 

3:发现路径下没有模块对应功能,只有一个空壳
在这里插入图片描述4:测试发现 pip uninsall 之后再安装也没有用;
5:最终处理方法是把 同时电脑下已安装的CAN模块,复制过来替换一下

>>> import can
>>> dir(can) 
['ASCReader', 'ASCWriter', 'AsyncBufferedReader', 'BLFReader', 'BLFWriter', 'BufferedReader', 'Bus', 'BusABC', 'BusState', 'CSVReader', 'CSVWriter', 'CanError', 'CanutilsLogReader', 'CanutilsLogWriter', 'CyclicSendTaskABC', 'LimitedDurationCyclicSendTaskABC', 'Listener', 'LogReader', 'Logger', 'Message', 'MessageSync', 'ModifiableCyclicTaskABC', 'MultiRateCyclicSendTaskABC', 'Notifier', 'Printer', 'RedirectReader', 'RestartableCyclicTaskABC', 'SqliteReader', 'SqliteWriter', 'ThreadSafeBus', 'VALID_INTERFACES', 
'__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'absolute_import', 'broadcastmanager', 'bus', 'detect_available_configs', 'interface', 'interfaces', 'io', 'listener', 'log', 'logging', 'message', 'notifier', 'rc', 'send_periodic', 'set_logging_level', 'thread_safe_bus', 'util']
>>> 

6:具体为什么我电脑不行也搞不清楚, 反正发现这种 pip install安装了一个空壳的模块,可以去官网下载之后在本地安装,或者复制其他人已成功安装的;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: The error message "cannot import name 'Business' from 'mimesis'" suggests that there is an issue with importing the `Business` class from the `mimesis` package. Here are some possible reasons for this error message: 1. `Business` class does not exist in the `mimesis` package: Double-check that the `Business` class actually exists in the version of `mimesis` that you are using. You can do this by looking at the package documentation or checking the source code. 2. `mimesis` package is not installed: Make sure that you have installed the `mimesis` package. You can do this by running the command `pip install mimesis` in your terminal. 3. Incorrect import statement: Check that your import statement is correct. The import statement should look something like this: `from mimesis.builtins import Business`. 4. Package version incompatibility: It is possible that the version of `mimesis` that you have installed is not compatible with the version of the Python interpreter that you are using. Try updating `mimesis` by running `pip install --upgrade mimesis` in your terminal. If none of these solutions work, you may need to provide more information about the code and environment you are using in order to diagnose the problem. ### 回答2: 在Python中,通常我们使用`import`语句将其他模块的函数、类或变量引入到当前的模块中以进行使用。在你的问题中,`from mimesis import Business`这个`import`语句无法正常工作,因为在`mimesis`模块中找不到名为`Business`的内容。 一个可能的原因是你在使用的`mimesis`库版本中不存在`Business`模块。可以通过检查你的`mimesis`库的文档或更新库的版本来解决这个问题。确保你使用的是最新版本的`mimesis`库,并查看文档以确定是否有任何关于`Business`模块的更改或替代模块。 另外一个可能的原因是你的代码中存在拼写错误。请确保你的代码中正确地书写了`from mimesis import Business`这一行,并且`Business`的大小写与模块中的一致。 如果以上解决方法均未成功,你可以考虑在`mimesis`库中使用其他可用的模块,或者尝试使用其他库来满足你的需求。 ### 回答3: "Mimesis" 是一个 Python 库,可以生成伪造数据,例如姓名、地址和电子邮件等。当出现 "cannot import name 'Business' from 'mimesis'" 错误时,意味着无法从 "mimesis" 库中导入 'Business' 模块。 这个错误通常是由于以下原因导致的: 1. 模块未安装:如果你还没有安装 "mimesis" 库,你将无法导入其中的任何模块。请确保你已经通过合适的方式安装了该库,例如使用 pip 命令运行 'pip install mimesis'。 2. 版本不匹配:如果你的 "mimesis" 库版本太旧,可能会导致某些模块无法导入。尝试升级库到最新版本,可以使用 'pip install --upgrade mimesis' 命令来进行升级。 3. 名称错误:如果你在代码中错误地将 'Business' 作为导入的模块名称(或者在库中找不到 'Business' 模块),则会出现这个错误。请确保你正确指定了模块的名称,例如 'from mimesis.business import Business'。 总结来说,要解决 "cannot import name 'Business' from 'mimesis'" 错误,你应该重新检查代码中的导入语句是否正确,确保库已经安装并且版本匹配。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值