导入错误:在 Windows 7 python 2.7 和 python 3.3 中没有名为 serial 的模块
我正在尝试安装 python 串行驱动程序.我做了如下一些步骤:
I am trying to install python serial driver. I have done some steps as follows:
我在我的电脑上安装了pyserial-2.7.win32.exe;
I installed the pyserial-2.7.win32.exe on my pc;
我写了这个python文件.
I wrote this python file.
#coding=gb18030
import serial
import time
import random
class EMCTest:
def __init__(self, Port="COM25"): # Port =3: COM4(According To You PC Environment, It Needs to Be Changed Before Testing.)
self.l_serial = None
self.port = Port
当我在 python 2.7 中运行 *.py 文件时,我得到以下输出
When I run *.py file in python 2.7 I get the following output
Traceback (most recent call last):
File "C:\Users\davwang\Desktop\X100.py", line 4, in <module>
import serial
ImportError: No module named serial
我对几乎所有导入的模块都遇到了类似的问题.我无法弄清楚,因为使用 pip install 是我一直在做的事情.我用非常讨厌和不雅的方式解决
I had a similar problem with nearly all imported modules. I couldn’t figure it out, because using pip install was what i have done all the time. I solches with a very nasty and unelegant way
import sys
sys.path.insert(0, u'/…/…/…/python2.7/site-packages')
我相信还有另一种方法,但我已经好几个星期没有找到了,这实际上对我有用.
I believe that there is another way, but i haven’t found one in weeks and this actually worked for me.