문태현
문태현

Reputation: 81

AttributeError: module 'serial' has no attribute 'Serial'

from serial import serial
joystick = serial.Serial("COM3", 9600)
joystick_x = joystick.write('0')
if joystick_x==1023:
    print("Right")
elif joystick_x != 1023:
    print("Not right");

and I received error message:

Traceback (most recent call last):
  File "C:/Users/Mine_science/Desktop/snu6/산출물/arduino.py", line 1, in <module>
    from serial import serial
  File "C:\Users\Mine_science\AppData\Local\Programs\Python\Python35\lib\site-packages\serial\serial\__init__.py", line 13, in <module>
    from serial.serialutil import *
ImportError: No module named 'serial.serialutil'

also Can you give me some advices to get each pin.

Upvotes: 7

Views: 46467

Answers (7)

Dar&#237;o
Dar&#237;o

Reputation: 101

Recently I had same error. Reason for that I came in thus post.

I have using spyder version 6, installed with flatpak, before I used spyder 5.4.2 (native of debian's repositories).

Was strange because an old script worked fine, then I thinked if proof the same script in Jupyter Notebook? and no problem! then I proof in Pyzo, zero problem, further I decided reinstall spyder 5.4.2, and surprise, it work:

import serial

puerto_serial = '/dev/ttyACM0'
baud_rate = 9600
timeout = 10
    
arduino = serial.Serial(puerto_serial, baud_rate, timeout=timeout)

My humble opinion, if is problem of IDE?

Upvotes: 0

NorthernJon
NorthernJon

Reputation: 1

I found that the below worked when I encountered this same problem:

from serial import *

Upvotes: 0

pschl
pschl

Reputation: 19

I wanted to use minimalmodbus and got the same error message as in the title of this post. What worked for me:

sudo apt install python-is-python3

Apparently there was some confusion between python 2 and 3 and python-is-python3 resolved it.

Upvotes: 0

Willian Calera
Willian Calera

Reputation: 31

I was getting the same error, but what works for me was:

  1. uninstall serial : pip3 uninstall serial
  2. uninstall pyserial: pip3 uninstall pyserial
  3. reinstall a previous version of pyserial: pip3 install pyserial==3.3 (I had 3.5 version)

Upvotes: 2

Pawan Dubey
Pawan Dubey

Reputation: 21

uninstalling python and pyserial package completely and then

installing python(python 3 in my case) back -

for all users and add Paths correctly

and then use

pip3 for installing pyserial

fixed all my issues

Upvotes: 2

Luis Jose
Luis Jose

Reputation: 754

I installed serial library using "pip3 install serial" and get the same error even calling the library using "import serial". Then I found that if first UNINSTALL serial:

pip3 uninstall serial

and then install pyserial:

pip3 install pyserial

fixed the problem for python 3.

Upvotes: 33

yampelo
yampelo

Reputation: 512

Looking at the documentation it looks like you only need to do

import serial

instead of

from serial import serial

http://pyserial.readthedocs.io/en/latest/shortintro.html

Upvotes: 1

Related Questions