Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PYserial basics?
#1
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?
Reply
#2
do you have a file named serial.py?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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.
Reply
#4
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(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?
Reply
#6
If you had - this could be cause of the problem. Unfortunately, now I don't have another idea
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
Can you do
import os
import serial
print(os.path.abspath(serial.__file__))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
Can you run pip list | grep serial? If you install the serial package after the pyserial package, that can mask it.
Reply
#9
(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
Reply
#10
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Learned Python Basics, what now? muzikman 20 5,983 Oct-11-2021, 01:34 AM
Last Post: Underscore
  [split] Debugging scripts basics tultalk 5 3,077 Apr-25-2020, 01:02 AM
Last Post: menator01
  Debugging scripts basics bako 8 3,495 Apr-24-2020, 06:18 AM
Last Post: Larz60+
  Problem with basics Wraith2102 2 1,993 Jun-17-2019, 06:51 PM
Last Post: perfringo
  Dictionary Basics pythonjm 5 3,505 Nov-26-2018, 11:11 PM
Last Post: pythonjm
  What to do after learning python basics xyzabc12310000 1 2,851 May-20-2018, 11:43 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020