Python Forum
pyserial/serial "has no attribute 'Serial' "
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyserial/serial "has no attribute 'Serial' "
#1
Hi there ! glad to discover this forum.

first, i am a beginner, i want to learn Python etc.

i was typing this program :

import serial 
serial_port = serial.Serial(port = "COM3", baudrate = 9600)
serial_port.readline()
and i get this error code :

Error:
File "c:\Users\Mérill\Desktop\pytharduino2\ardseri.py3", line 2, in <module> serial_port = serial.Serial(port = "COM3", baudrate = 9600) ^^^^^^^^^^^^^ AttributeError: module 'serial' has no attribute 'Serial'
i tried to reinstall the pyserial library, uninstall the serial library,

i tried the method
from serial import Serial


it does not help. i have an other error code

Error:
File "c:\Users\Mérill\Desktop\pytharduino2\ardseri.py3", line 1, in <module> from serial import Serial ^^^^^^^^^^^^^^^^^^^^^^^^^ ImportError: cannot import name 'Serial' from 'serial' (unknown location)
so i tried a lot of different common solutions to fix this problem. But i am stuck Sad

i am using Python3.x
Reply
#2
This seems to work for me. Do get an error because I do not have a COM3 port. I'm on a linux os

from serial import Serial
serial_port = Serial(port='COM3', baudrate=9600)
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
How did you reinstall the pyserial library?

Please show entire error trace. I would also like to know how you are running the program. Command line? IDE (if so, which)?

My first guess is you are not importing pyserial in the Python you are using to run the program. Are you using a virtual environment? Did you activate the environment before using pip install (assuming you used pip install)?
Reply
#4
(Aug-23-2023, 06:28 PM)deanhystad Wrote: How did you reinstall the pyserial library?

Please show entire error trace. I would also like to know how you are running the program. Command line? IDE (if so, which)?

My first guess is you are not importing pyserial in the Python you are using to run the program. Are you using a virtual environment? Did you activate the environment before using pip install (assuming you used pip install)?

yes i did reinstall. Several times

File "c:\Users\Mérill\Desktop\pytharduino2\ardseri.py3", line 2, in <module>
    serial_port = serial.Serial(port = "COM3", baudrate = 9600)
                  ^^^^^^^^^^^^^
AttributeError: module 'serial' has no attribute 'Serial'
Reply
#5
(Aug-23-2023, 06:30 PM)gowb0w Wrote:
(Aug-23-2023, 06:28 PM)deanhystad Wrote: How did you reinstall the pyserial library?

Please show entire error trace. I would also like to know how you are running the program. Command line? IDE (if so, which)?

My first guess is you are not importing pyserial in the Python you are using to run the program. Are you using a virtual environment? Did you activate the environment before using pip install (assuming you used pip install)?

yes i did reinstall. Several times

File "c:\Users\Mérill\Desktop\pytharduino2\ardseri.py3", line 2, in <module>
    serial_port = serial.Serial(port = "COM3", baudrate = 9600)
                  ^^^^^^^^^^^^^
AttributeError: module 'serial' has no attribute 'Serial'

sorry i'm tired, i posted the last reply without thinking Big Grin

i did reinstall several times pyserial

and the error message is this one, i have nothing else.

Error:
File "c:\Users\Mérill\Desktop\pytharduino2\ardseri.py3", line 2, in <module> serial_port = serial.Serial(port = "COM3", baudrate = 9600) ^^^^^^^^^^^^^ AttributeError: module 'serial' has no attribute 'Serial'
Reply
#6
ok, i found a solution :

simply i reinstalled python on my computer 8D

made some restarts between uninstall and reinstall

and the error message does not come anymore.
Reply
#7
Now we'll never know what the problem was.

My guess is still that you installed pyserial in one Python and used a different Python to run your program. This is pretty common. What are you using to write your Python programs? How do you install python modules? How do you run your programs? Your error is related to some procedure that you did incorrectly. It will reappear.
Reply
#8
Maybe there was a file named serial.py next to your script. In this case, Python imports this instead from site-packages.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#9
(Aug-23-2023, 08:10 PM)deanhystad Wrote: Now we'll never know what the problem was.

My guess is still that you installed pyserial in one Python and used a different Python to run your program. This is pretty common. What are you using to write your Python programs? How do you install python modules? How do you run your programs? Your error is related to some procedure that you did incorrectly. It will reappear.

i'm using Visual studio code. but i tried with python shell and i had the same problem.
Reply
#10
(Aug-24-2023, 07:18 AM)DeaD_EyE Wrote: Maybe there was a file named serial.py next to your script. In this case, Python imports this instead from site-packages.

ah yes, i thought of it. but i checked and it was not the case.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Waiting for input from serial port, then move on KenHorse 3 1,097 Apr-17-2024, 07:21 AM
Last Post: DeaD_EyE
  MCU reboots after opening Serial port when ran from Raspberry PI zazas321 3 451 Mar-19-2024, 09:02 AM
Last Post: zazas321
  importing serial Fklein23 2 1,134 Jul-05-2023, 01:32 PM
Last Post: deanhystad
  Serial Port As Global Prasanjith 2 1,517 Mar-23-2023, 08:54 PM
Last Post: deanhystad
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 833 Mar-21-2023, 10:06 PM
Last Post: deanhystad
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 4,110 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  time setup for realtime plotting of serial datas at high sampling rate alice93 6 3,762 Jan-07-2022, 05:41 PM
Last Post: deanhystad
  serial input/output barryjo 3 2,527 Dec-27-2021, 11:57 PM
Last Post: barryjo
  python serial port barryjo 2 1,662 Dec-27-2021, 11:09 PM
Last Post: barryjo
  Help reading data from serial RS485 korenron 8 14,042 Nov-14-2021, 06:49 AM
Last Post: korenron

Forum Jump:

User Panel Messages

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