Reputation: 3
I am trying to install python serial driver. I have done some steps as follows:
I installed the pyserial-2.7.win32.exe on my pc;
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
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
Upvotes: 0
Views: 18952
Reputation: 1338
A few things could be wrong. Is your Python x86 or x64? Did the installer actually install (look in site-packages).
Instead of doing complicated work finding what's wrong with your install, try installing with pip the easiest way to install libraries. Use pip install pyserial
. This is widely considered the best way to install Python libraries. It automatically deals with dependencies, operating system and x86 versus x64.
EDIT: It looks to me that the python folder isn't in your system path. You can sys.path.append("/path/to/python/")
, or you can run set PYTHONPATH=%PYTHONPATH%;<Path/to/python>
in cmd.
Upvotes: 2
Reputation: 89
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.
Upvotes: 1