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,669
  • 9
  • 47
  • 52
PwnDoS
  • 21
  • 1
  • 4
  • 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. – jasonharper Jun 29 '20 at 21:52
  • or [Python AttributeError: 'module' object has no attribute 'Serial'](https://stackoverflow.com/q/11403932) – gre_gor Jun 29 '20 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. – PwnDoS Jul 01 '20 at 00:11

2 Answers2

0

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

elbashmubarmeg
  • 330
  • 1
  • 9
  • 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'. – PwnDoS Jul 01 '20 at 00:13
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!

PwnDoS
  • 21
  • 1
  • 4