Ori Halyo
Ori Halyo

Reputation: 61

"ImportError: No module named serial" - after installing pyserial

I'm writing a project in python which should eventually running on LinkIt One IoT device.

I've written some test code to check whether I am able to connect between Arduino IDE to python (I am working with Pycharm).

the test code is:

import serial
import time

arduino = serial.Serial('COM1', 115200, timeout=.1)

time.sleep(1) #give the connection a second to settle

arduino.write("Hello from Python!")

while True:
    data = arduino.readline()
    if data:
        print data.rstrip('\n')

when I am running to code I am getting:

C:\Users\אורי\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/אורי/PycharmProjects/untitled2/test.py

Traceback (most recent call last): File "C:/Users/����/PycharmProjects/untitled2/test.py", line 1, in import serial ImportError: No module named serial

Upvotes: 6

Views: 22051

Answers (2)

dsgdfg
dsgdfg

Reputation: 1510

Sometimes we mix things up ourselves. But we won't realize that.

On linux or windows :

  • A = Os required Python version(like:64bit or 32Bit, 2.7.x, 3.X.X, etc.)
  • B = The version we need.(like:x86 arch, 1.6.X, 2.6.X, 3.0, etc.)
  • C = Another version we need(like:X64)

Every IDLE (which is linked to /bin or OS.PATH) work on native directory (os never touch this things.). Install a library system-wide but try to call external IDLE or install library locally and call from system-wide.

Which installer (I do not recommend) used system environment variables, but maybe you want install a library locally!

Short answer:

  1. Go to your idle directory(what you want(used))
  2. Download your module
  3. Extract somewhere
  4. Use version of Python (which you want, joined dir(1.)) python /extract-dir/setup.py *kwargs

Note :

import sys
sys.path.append("C:\Python27\Lib\site-packages")

Don't do that, because you aren't standard user !

I hope it helps. I'm sorry if you lost time.

Upvotes: 0

Peko Chan
Peko Chan

Reputation: 365

how did you install your serial module? If you want to make sure It will be detected, go into your console

pip install serial

and run your code from the console too

python test.py # make sure your console is in the right folder path

or

find where the module is installed, something like "C:\Python27\Lib\site-packages"

import sys
sys.path.append("C:\Python27\Lib\site-packages") # this is where python stores modules, yours could be different 
import serial

Upvotes: 4

Related Questions