How to import the library function quot;import canquot; in Python(如何在Python中导入库函数IMPORT CANQUOT;)
本文介绍了如何在Python中导入库函数&IMPORT CAN";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Ubuntu。我想要向总线发送垃圾邮件,并使用Wireshark查看数据包。我试图运行如下所示的Python代码,但它抛出了以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'can'
我的代码:
import time, can
bustype = 'socketcan'
channel = 'vcan0'
def producer(id):
# :param id: Spam the bus with messages including the data id.
bus = can.interface.Bus(channel=channel, bustype=bustype)
for i in range(10):
msg = can.Message(arbitration_id=0xc0ffee, data=[id, i, 0, 1, 3, 1, 4, 1], extended_id=False)
bus.send(msg)
# Issue #3: Need to keep running to ensure the writing threads stay alive.
time.sleep(1)
producer(10)
推荐答案
Ubuntu18.04及更高版本
在Ubuntu 18.04及更高版本中,默认的Ubuntu存储库提供了python-can和python3-can。打开终端并输入:
sudo apt update
sudo apt install python3-can # for Python 3.x
或
sudo apt update
sudo apt install python python-can # for Python 2.x
若要安装Canard(用于与控制器区域网络(CAN)交互的库),您必须使用pip。
python3 -m pip install --user CANard # for Python 3.x
或
python -m pip install --user CANard # for Python 2.x
这篇关于如何在Python中导入库函数&IMPORT CAN";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:如何在Python中导入库函数&IMPORT CAN";
基础教程推荐
猜你喜欢
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
