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
No module named serial
提问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 serial
package installed.
您没有安装serial
软件包。
Try pip install serial
to install the module.
尝试pip install serial
安装模块。
Alternatively, install it in binary form from here:
或者,从这里以二进制形式安装它:
Note that you always install precompiled binaries at your own risk.
请注意,您始终需要自担风险安装预编译的二进制文件。
回答by xrisk
You must pip install pyserial
first.
你必须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 Soumik Debnath
Download this file :- (https://pypi.python.org/packages/1f/3b/ee6f354bcb1e28a7cd735be98f39ecf80554948284b41e9f7965951befa6/pyserial-3.2.1.tar.gz#md5=7142a421c8b35d2dac6c47c254db023d):
cd /opt
sudo tar -xvf ~/Downloads/pyserial-3.2.1.tar.gz -C .
cd /opt/pyserial-3.2.1
sudo python setup.py install
回答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库。有多种安装方法:-
pip install pyserial
- Download zip from pyserial and save extracted library in Lib>>site-packages folder of Python.
- Download wheel and install wheel using command:
pip install <wheelname>
pip install pyserial
- 从 pyserial 下载 zip 并将提取的库保存在 Python 的 Lib>>site-packages 文件夹中。
- 使用命令下载轮子并安装轮子:
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
- Firstly uninstall pyserial using the command
pip uninstall pyserial
- Then go to https://www.lfd.uci.edu/~gohlke/pythonlibs/
- download the suitable pyserial version and then go to the directory where the file is downloaded and open cmd there
- then type pip install "filename"(without quotes)
- 首先使用命令卸载pyserial
pip uninstall pyserial
- 然后去https://www.lfd.uci.edu/~gohlke/pythonlibs/
- 下载合适的pyserial版本,然后进入下载文件的目录并在那里打开cmd
- 然后输入 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.
上述命令将使用系统解释器对其进行索引。