可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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:
回答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:-
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>
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"