Python Forum

Full Version: PYserial basics?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
import serial
import time
ser = serial.Serial("/dev/ttyS0", baudrate=115200)
W_buf = ["AT\r\n", "AT+CMGS=\"15555555555\"\r\n", "Helloworld"]
ser.write(W_buf[0])
ser.flushInput()
Error:
Traceback (most recent call last): File "send_message.py", line 3, in <module> ser = serial.Serial("/dev/ttyS0", baudrate=115200) AttributeError: 'module' object has no attribute 'Serial'
#pythonnoob

I just copied and pasted the code and I don't really get this error message. The pyserial package was installed using PIP. What am I doing wrong?
do you have a file named serial.py?
(Apr-26-2020, 04:57 AM)buran Wrote: [ -> ]do you have a file named serial.py?

not that I'm aware of... If I knew how to check the PIP packages I would.
no, I mean your own file serial.py in the same folder as the script you run. That would shadow the package you import. It's a common newbie mistake.
(Apr-26-2020, 05:01 AM)buran Wrote: [ -> ]no, I mean your own file serial.py in the same folder as the script you run. That would shadow the package you import. It's a common newbie mistake.

No. I don't. Is that the problem?
If you had - this could be cause of the problem. Unfortunately, now I don't have another idea
Can you do
import os
import serial
print(os.path.abspath(serial.__file__))
Can you run pip list | grep serial? If you install the serial package after the pyserial package, that can mask it.
(Apr-26-2020, 06:52 AM)buran Wrote: [ -> ]Can you do
import os
import serial
print(os.path.abspath(serial.__file__))

/usr/local/lib/python2.7/dist-packages/serial/__init__.pyc
/usr/local/lib/python2.7/dist-packages/serial/__init__.pyc
I figured it out. Apparently I had another PIP package called "serial" installed which totally doesn't do what I want. Anybody know how to handle with conflicts like that?

Name: pyserial
Version: 3.4
Summary: Python Serial Port Extension
Home-page: https://github.com/pyserial/pyserial
Author: Chris Liechti
Author-email: [email protected]
License: BSD
Location: /usr/lib/python2.7/dist-packages
Requires:

Name: serial
Version: 0.0.97
Summary: A framework for serializing/deserializing JSON/YAML/XML into python class instances and vice versa
Home-page: https://bitbucket.com/davebelais/serial.git
Author: David Belais
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python2.7/dist-packages
Requires: future, iso8601, pyyaml
Pages: 1 2