Python pyserial,ImportError:没有名为 serial 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33086281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:44:16  来源:igfitidea点击:

pyserial, ImportError: No module named serial

pythonpyserial

提问by Andrea Diaz

I know this question have been asked several times, but none of the solutions I saw solved my problem.

我知道这个问题已经被问过好几次了,但是我看到的解决方案都没有解决我的问题。

I have been trying to use the serial library from Sublime Text 2 in my mac.

我一直在尝试在我的 Mac 中使用 Sublime Text 2 中的串行库。

import serial

Everytime I call this library, I get this message:

每次我调用这个库时,我都会收到以下消息:

  Traceback (most recent call last):
    File "/Users/andreapatri/Desktop/test.py", line 1, in <module>
      import serial
  ImportError: No module named serial
  [Finished in 0.0s with exit code 1] 

I already installed python 3

我已经安装了 python 3

brew install python3

and pyserial

和 pyserial

sudo pip install pyserial

I am new using mac. Can you please tell me how to fix the error?

我是新人,使用 mac。你能告诉我如何解决这个错误吗?

回答by Andrea Diaz

I solved this issue with this:

我用这个解决了这个问题:

sudo easy_install pyserial

回答by Masoud

This commnad solved my problem on ubuntu:

这个命令解决了我在 ubuntu 上的问题:

apt install python3-serial

回答by Jonathan Carter Hebert

Using python pip:

使用 python pip:

pip install pyserial

回答by Alex Zh

try to use pip3 instead of pip

尝试使用 pip3 而不是 pip

pip3[.X] install pyserial

pip3[.X] 安装pyserial

.X is your python3 version

.X 是你的 python3 版本

回答by Ivar Simensen

Use python3 for running your script. If you try to use python, you will get this error message.

使用 python3 来运行你的脚本。如果您尝试使用 python,您将收到此错误消息。

python3 <scriptname>.py