Ubuntu ImportError: No module named serial

解决办法:在命令端输入以下命令

  1. sudo apt-get update
  2. sudo apt install python-pip
  3. sudo apt install python3-pip
  4. sudo pip install pyserial
    若没报错则继续进行第5步,在这里有人出错了
    在这里插入图片描述
    那么我们升级pip,输入命令:sudo pip install --upgrade pip
    然后我们看下pip版本,输入命令:pip -V
    此时,又有一个错误,ImportError: cannot import name main
    在这里插入图片描述
    原因是升级了pip,原来的命令有所改变,解决办法:
    sudo gedit /usr/bin/pip
    将原来的:
    在这里插入图片描述
    改为
    在这里插入图片描述
    注意__main__左右的下划线是两个下划线
    参考链接:pip升级后Import Error:cannot import name main解决方案

至此,在输入命令:pip -V ,就没有问题
在这里插入图片描述
再重新输入第4步命令: sudo pip install pyserial
5. sudo pip3 install pyserial
再次出现之前的错误,原因是未能区分pip和pip3
在这里插入图片描述
按照原来的步骤即可
6. sudo pip3 install --upgrade pip3
若出现错误,查看版本,输入命令:pip3 -V
显示ImportError: cannot import name ‘main’,则修改文件,输入命令:sudo gedit /usr/bin/pip3
将原来的:
在这里插入图片描述
改为
在这里插入图片描述
注意__main__左右的下划线是两个下划线
7. 再重新输入命令:sudo pip3 install pyserial

若出现下面的错误

  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f39c0ceea10>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pyserial/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f39c0ceed10>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pyserial/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f39c0ceefd0>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pyserial/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f39c0d04f90>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pyserial/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f39c0d04e10>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pyserial/
  Could not find a version that satisfies the requirement pyserial (from versions: )
No matching distribution found for pyserial

在这里插入图片描述解决方案:
改为国内镜像源下载

常用国内源:

清华:https://pypi.tuna.tsinghua.edu.cn/simple/

阿里云:http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/

豆瓣:http://pypi.douban.com/simple/

以清华大学镜像源下载为例:
安装指令:pip install xxx(包名) -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn

-i :后为镜像源地址

–trusted-host :后边指的是host,例清华大学镜像源地址为 https://pypi.tuna.tsinghua.edu.cn/simple/,host就是指http://和/之间的部分,即pypi.tuna.tsinghua.edu.cn
例如:

pip install pyserial -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn

在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值