解决AttributeError: module ‘serial‘ has no attribute ‘Serial‘

这篇具有很好参考价值的文章主要介绍了解决AttributeError: module ‘serial‘ has no attribute ‘Serial‘。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


前言

最近在搞上位机时遇到了报错AttributeError: module ‘serial’ has no attribute ‘Serial’,翻译过来就是serial类没有Serial对象。然后卡了一个小时才解决,试了网上很多方法,最后才发现报错原因,这问题python也有责任。
下面说下一般的解决方法。


1.serial与pyserial只能安装一个

python3之后串口都改为pyserial,serial与pyserial区别不大,直接用pyserial就可以了。
而我遇到的问题是同时安装了serial与pyserial,导致报错,两者并不能同时安装,这点在pip时应该给予提示。所以如果是这个问题,同时卸载serial与pyserial,然后只安装pyserial。

2.重装pyserial

这是网上最多人说的方法,一言不合就重装。网上还有人说没有安装pyserial,这是错误的说法,如果没有安装会报错无法import serial(注意用pyserial也是import serial),而不是报这个错。

3.不能出现文件名为serial.py

原因很简单,import serial时会跳转到自己的文件,而不是官方库。

4.其他

在用serial.Serial时注意要加参数timeout,否则可能会卡在里面。


结语

最近在搞机械臂相关项目,过段时间会开源部分代码,介绍下涉及的上位机驱动和运动学算法。文章来源地址https://www.toymoban.com/news/detail-786207.html

到了这里,关于解决AttributeError: module ‘serial‘ has no attribute ‘Serial‘的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【已解决】AttributeError: module ‘numpy‘ has no attribute ‘int‘.

    AttributeError: module ‘numpy’ has no attribute ‘int’. np.int was a deprecated alias for the builtin int . To avoid this error in existing code, use int by itself. Doing this will not modify any behavior and is safe. 新版本的numpy里面没有np.int了。 第一种,降低numpy版本,安装1.20以下的版本。 第二种,修改源码。 将 修

    2024年02月14日
    浏览(26)
  • 成功解决AttributeError: module ‘numpy‘ has no attribute ‘float‘.

    AttributeError: module ‘numpy’ has no attribute ‘float’. np.float was a deprecated alias for the builtin float . To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here. The aliases was originally deprecated in NumPy 1.20; for

    2024年02月16日
    浏览(47)
  • AttributeError: module ‘numpy‘ has no attribute ‘array‘解决办法

    NumPy是Python中重要的数值计算库,提供了强大的数组操作和数学函数。然而,有时候我们可能会在使用NumPy时遇到\\\"AttributeError: module ‘numpy’ has no attribute ‘array’\\\"的错误提示,这可能会让一些用户感到困惑。在本文中,我们将分享如何解决这个问题的方法,并帮助读者更好地

    2024年02月13日
    浏览(47)
  • AttributeError: module ‘openai‘ has no attribute ‘error‘解决方案

      大家好,我是爱编程的喵喵。双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中。从事机器学习以及相关的前后端开发工作。曾在阿里云、科大讯飞、CCF等比赛获得多次Top名次。现为CSDN博客专家、人工智能领域优质创作者。喜欢通过博客创作

    2024年01月17日
    浏览(32)
  • 完美解决 AttributeError: module ‘torch.utils‘ has no attribute ‘data‘

    完美解决 AttributeError: module ‘torch.utils’ has no attribute ‘data’ 下滑查看解决方法 AttributeError: module ‘torch.utils‘ has no attribute ‘data‘ 这个错误通常是由于使用了过时的torch版本导致的。在旧的torch版本中,torch.utils.data模块是存在的,但在新版的torch中已经被移除,因此会出现

    2024年02月07日
    浏览(34)
  • 解决AttributeError: module ‘tensorflow.python.keras‘ has no attribute ‘Model‘

    目录 解决AttributeError: module \\\'tensorflow.python.keras\\\' has no attribute \\\'Model\\\' 引言 错误原因 解决方案 1. 升级TensorFlow版本 2. 正确导入模块 3. 检查其他依赖项 4. 重新安装TensorFlow 结论 实际应用场景: 引言 在使用TensorFlow的过程中,您可能会遇到各种错误。其中之一是​ ​AttributeError:

    2024年02月05日
    浏览(40)
  • 【Tensorboard报错解决】AttributeError:module ‘distutils‘ has no attribute ‘version‘

    根据这里所说,tensorboardX好像寄了,但是Pytorch官方给出了SummaryWriter作为替代品。 环境是Torch1.10.2+cu113,tensorboard2.8.0。 试图使用如下命令 导入tensorboard,报错: 根据这里的描述,原因是setuptools包版本过高,需要降低版本。 这里给出另外一个解决方案。打开Anacondaenvstorche

    2024年02月11日
    浏览(30)
  • 解决 AttributeError: module ‘tensorflow‘ has no attribute ‘contrib‘ 等类似的问题

    使用tensorflow2.x版本的时候,使用调用tensorflow1.x函数的代码时,常常会出现module ‘tensorflow’ has no attribute ‘contrib’这样的问题,这是由于tensorflow2.x废弃了很多tensorflow1.x API接口,本文针对常见的几种错误来使tf2.0不降版本也能运行代码。 1、报错AttributeError: module ‘tensorflow’

    2024年02月02日
    浏览(34)
  • AttributeError: module ‘torch.nn‘ has no attribute ‘SiLU‘问题的解决办法

    AttributeError: module \\\'torch.nn\\\' has no attribute \\\'SiLU\\\'        这个问题的原因是这个版本的torch中的torch.nn函数表里面没有这个SiLU函数,需要更高版本的torch,在官方的文档中我们就可以查看这个版本里有没有包含这个模块。 官方文档1.1.0    红框选择 torch 版本,我的版本是1.1.0,搜

    2024年02月13日
    浏览(41)
  • AttributeError: module ‘numpy‘ has no attribute ‘ndarray‘(最新版解决,综合多篇)

    1.进入你 所在环境,分别卸载掉原有的 numpy与pandas 2. 重新安装numpy与pandas,记住先安装numpy,然后安装pandas。 语句1:pip install numpy==1.21.5 -i https://pypi.tuna.tsinghua.edu.cn/simple some-package 语句2:pip install pandas==1.4.3 -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

    2024年02月12日
    浏览(77)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包