Python 没有名为 serial 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33267070/
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 13:07:03  来源:igfitidea点击:

No module named serial

python

提问by Amber.G

and I got a question when I run my Python code.

我在运行 Python 代码时遇到了一个问题。

I installed Python 2.7 on Windows 7, bit 64. I got an error "No module named serial" when I compiled my code:

我在 Windows 7 上安装了 Python 2.7,位 64。当我编译我的代码时出现错误“No module named serial”:

import serial

ser = serial.Serial("COM5", 9600)

ser.write("Hello world")

x = ser.readline()

print(x)

I tried many ways to crack this problem, such as installed Canopy to setup virtual environment, make sure 'pip' is there, no Python v 3.x installed. But still cannot get it out.

我尝试了很多方法来破解这个问题,比如安装 Canopy 来设置虚拟环境,确保 'pip' 在那里,没有安装 Python v 3.x。但是还是拿不出来。

Any advice would be appreciated.

任何意见,将不胜感激。

回答by Victor

You do not have serialpackage installed.

您没有安装serial软件包。

Try pip install serialto install the module.

尝试pip install serial安装模块。

Alternatively, install it in binary form from here:

或者,从这里以二进制形式安装它:

Install Pyserial for Windows

为 Windows 安装 Pyserial

Note that you always install precompiled binaries at your own risk.

请注意,您始终需要自担风险安装预编译的二进制文件。

回答by xrisk

You must pip install pyserialfirst.

你必须pip install pyserial先。

回答by Hosack

Serial is not included with Python. It is a package that you'll need to install separately.

串行不包含在 Python 中。这是一个您需要单独安装的软件包。

Since you have pip installed you can install serial from the command line with:

由于您已经安装了 pip,您可以使用以下命令从命令行安装串行:

pip install pyserial

Or, you can use a Windows installer from here. It looks like you're using Python 3 so click the installer for Python 3.

或者,您可以从这里使用 Windows 安装程序。看起来您使用的是 Python 3,因此请单击 Python 3 的安装程序。

Then you should be able to import serial as you tried before.

然后您应该能够像之前尝试的那样导入序列号。

回答by Johnny

You must have the pyserial library installed. You do not need the serial library.Therefore, if the serial library is pre-installed, uninstall it. Install the pyserial libray. There are many methods of installing:-

您必须安装 pyserial 库。您不需要串口库。因此,如果预装了串口库,请将其卸载。安装pyserial库。有多种安装方法:-

  1. pip install pyserial
  2. Download zip from pyserial and save extracted library in Lib>>site-packages folder of Python.
  3. Download wheel and install wheel using command: pip install <wheelname>
  1. pip install pyserial
  2. 从 pyserial 下载 zip 并将提取的库保存在 Python 的 Lib>>site-packages 文件夹中。
  3. 使用命令下载轮子并安装轮子: pip install <wheelname>

Link: https://github.com/pyserial/pyserial/releases

链接:https: //github.com/pyserial/pyserial/releases

After installing Pyserial, Navigate to the location where pyserial is installed. You will see a "setup.py" file. Open Power Shell or CMD in the same directory and run command "python setup.py install". Now you can use all functionalities of pyserial library without any error.

安装 Pyserial 后,导航到 pyserial 的安装位置。您将看到一个“setup.py”文件。在同一目录中打开 Power Shell 或 CMD 并运行命令“ python setup.py install”。现在您可以使用 pyserial 库的所有功能而不会出现任何错误。

回答by satinder singh

  1. Firstly uninstall pyserial using the command pip uninstall pyserial
  2. Then go to https://www.lfd.uci.edu/~gohlke/pythonlibs/
  3. download the suitable pyserial version and then go to the directory where the file is downloaded and open cmd there
  4. then type pip install "filename"(without quotes)
  1. 首先使用命令卸载pyserial pip uninstall pyserial
  2. 然后去https://www.lfd.uci.edu/~gohlke/pythonlibs/
  3. 下载合适的pyserial版本,然后进入下载文件的目录并在那里打开cmd
  4. 然后输入 pip install "filename"(不带引号)

回答by Vikas

First use command

首先使用命令

pip uninstall pyserial

Then run again

然后再次运行

 pip install pyserial

The above commands will index it with system interpreter.

上述命令将使用系统解释器对其进行索引。