2

I've seen a lot of questions on here that have this same issue, but I haven't found a solution that works yet. I'm trying to run this face tracking program, but I can't get it to work. I know that the program says that it's written for python 2.7, but as far as I know there isn't that much of a difference in the language structure, right? I have a pretty firm understanding of the basics of python, but I'm still going through school.

The issue is in the title, I downloaded pyserial, open-cv and numpy through the terminal on mac into /3.8/bin. However, when I try to run the code below, it throws an AttributeError like I don't have serial installed. Am I missing something, or misreading something? Any help would be greatly appreciated.

Input:

 #import all the required modules
 import numpy as np
 import serial
 import time
 import sys
 import cv2
 arduino = serial.Serial('/dev/cu.usbmodem14201', 9600) 

Error:

Traceback (most recent call last):
 File "/Users/daPWNDAZ/Desktop/Arduino/Codes/FaceTracking/face.py", line 7, in <module>
 arduino = serial.Serial('/dev/cu.usbmodem14201', 9600)
AttributeError: module 'serial' has no attribute 'Serial'
gre_gor
6,66012 gold badges105 silver badges107 bronze badges
asked Jun 29, 2020 at 21:44
3
  • 1
    An error "like I don't have serial installed" would be an ImportError. This looks more like you have a serial.py file somewhere, that is being imported instead of the actual module. Do import serial; print(serial.__file__) to see where it is. Commented Jun 29, 2020 at 21:52
  • or Python AttributeError: 'module' object has no attribute 'Serial' Commented Jun 29, 2020 at 22:26
  • I looked in my directory and couldn't find any file named 'serial.py'. Jason's code returned a file named 'init.py'. I have a folder named "serial' in my directory, but that was installed when I ran pip. Commented Jul 1, 2020 at 0:11

2 Answers 2

0

Apparently you have a python script in your directory named "serial". Rename that file and you should be good

answered Jun 29, 2020 at 22:20
Sign up to request clarification or add additional context in comments.

1 Comment

I looked around in my directory and could only find a folder named 'serial'. I did find a 'serialcli.py' file, but again, not 'serial'.
0

I found an answer! I couldn't find any files named "serial", so I dug around a bit more in the answers gre_gor gave. It got fixed by uninstalling pyserial from the command line and reinstalling it (as suggested in the second link), which I could have sworn I had already done. I'm not getting any errors anymore, thank you all!

answered Jul 1, 2020 at 15:15

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.