No module named serial

匿名 (未验证) 提交于 2019-12-03 08:33:39

问题:

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

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

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.

Any advice would be appreciated.

回答1:

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

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

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.

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



回答2:

You must pip install pyserial first.



回答3:

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  


回答4:

You do not have serial package installed.

Try pip install serial to install the module.

Alternatively, install it in binary form from here:

Install Pyserial for Windows

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



回答5:

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:-

  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>

Link: 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.



回答6:

1)firstly uninstall pyserial using the command pip uninstall pyserial 2)then go to https://www.lfd.uci.edu/~gohlke/pythonlibs/ and serial for pyserial 3)download the suitable pyserial version and then go to the directory where the file is downloaded and open cmd there 4)then write pip install "file which is downloaded"



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!