import serial failure

J

J W Burton

I have installed both Python 2.7 AND Python 3.3 and the corresponding pyserial files from

ihttps://pypi.python.org/packages/any/p/pyserial/pyserial-2.7.win32.exe#md5=21555387937eeb79126cde25abee4b35n my

for 2.7

When I look in my Python27/Lib/site-packages/serial folder I see
package files

but when I run a program using import serial, I get an error
Traceback (most recent call last):
File "C:\Users\Jahree\serial.py", line 2, in <module>
import serial
File "C:\Users\Jahree\serial.py", line 5, in <module>
ser = serial.Serial(
AttributeError: 'module' object has no attribute 'Serial'

I'm guessing there is a path not set correctly - I'M STUCK

Please help.

Thanks

ps: the following is serial.py file I'm using for testing.

import time
import serial

# configure the serial connections (the parameters differs on the device you are connecting to)
ser = serial.Serial(
port='/dev/ttyUSB1',
baudrate=19200,
parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_TWO,
bytesize=serial.SEVENBITS
)

ser.open()
ser.isOpen()

print('Enter your commands below.\r\nInsert "exit" to leave the application.')

input=1
while 1 :
# get keyboard input
input = raw_input(">> ")
input = input(">> ")
if input == 'exit':
ser.close()
exit()
else:
# send the character to the device
# (note that I happend a \r\n carriage return and line feed to the characters - this is requested by my device)
ser.write(input + '\r\n')
out = ''
# let's wait one second before reading output (let's give device time to answer)
time.sleep(2)
while ser.inWaiting() > 0:
out += ser.read(4)

if out != '':
print(">>" ,out)
 
Z

Zachary Ware

I have installed both Python 2.7 AND Python 3.3 and the corresponding pyserial files from

ihttps://pypi.python.org/packages/any/p/pyserial/pyserial-2.7.win32.exe#md5=21555387937eeb79126cde25abee4b35n my

for 2.7

When I look in my Python27/Lib/site-packages/serial folder I see
package files

but when I run a program using import serial, I get an error
Traceback (most recent call last):
File "C:\Users\Jahree\serial.py", line 2, in <module>
import serial
File "C:\Users\Jahree\serial.py", line 5, in <module>
ser = serial.Serial(
AttributeError: 'module' object has no attribute 'Serial'

I'm guessing there is a path not set correctly - I'M STUCK

Please help.

Thanks

ps: the following is serial.py file I'm using for testing.

import time
import serial

Your file is named serial.py, so "import serial" in that file will try
to import itself. You can see this in the traceback you posted,
everything is coming from "C:\Users\Jahree\serial.py". Rename your
serial.py and things should work as expected.

Hope this helps,
 
P

Peter Otten

J said:
I have installed both Python 2.7 AND Python 3.3 and the corresponding
pyserial files from

ihttps://pypi.python.org/packages/any/p/pyserial/pyserial-2.7.win32.exe#md5=21555387937eeb79126cde25abee4b35n
my

for 2.7

When I look in my Python27/Lib/site-packages/serial folder I see
package files

but when I run a program using import serial, I get an error
Traceback (most recent call last):
File "C:\Users\Jahree\serial.py", line 2, in <module>
import serial
File "C:\Users\Jahree\serial.py", line 5, in <module>
ser = serial.Serial(
AttributeError: 'module' object has no attribute 'Serial'

I'm guessing there is a path not set correctly - I'M STUCK

Please help.

Thanks

ps: the following is serial.py file I'm using for testing.

Your choice of filename is unfortunate ;)
import time
import serial

The file is importing itself here. Rename your

C:\Users\Jahree\serial.py

to something unique, say

C:\Users\Jahree\myserial.py

delete

C:\Users\Jahree\serial.pyc

and everything should be OK.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top