0

thank you in advance.

I will try to keep it short.

I have an Arduino + IDE with a serial port that works fine. I downloaded Python 3.7.2, PySerial, and VPython. Installed all of them.

Installed PySerial through my MacBook terminal.

sudo easy_install pyserial 
Password: Searching for pyserial 
Best match: pyserial 3.4 
Adding pyserial 3.4 to easy-install.pth file

I installed VPython through the terminal too.

MacBook-3:~ myname$ pip list 
Package         Version 
FontTools       2.4     
numpy           1.9.1   
pip             18.1    
Polygon2        2.0.7   
pyserial        3.4     
setuptools      39.0.1  
TTFQuery        1.0.5   
VPython         6.11    
wxPython        3.0.0.0 
wxPython-common 3.0.0.0

and when I typed in help("modules") in the Python 3.7.2 shell I got this, which says PySerial is a module I have.

Please wait a moment while I gather a list of all available modules... PySerial _thread getopt resource YoutubeARDTOPY _threading_local getpass rlcompleter future _tkinter

I made a simple code on Arduino that writes to the serial port, verified and uploaded it. It works fine. Closed that port. Ran this code on Python 3.7.2 expecting this code to grab what is being sent to Arduinos serial port and start posting to Pythons serial port.

import serial #Import Serial Library
arduinoSerialData = serial.Serial('/dev/cu.usbmodem14101', 9600)
while (1==1):
    if (arduinoSerialData.inWaiting()>0):
        myData = arduinoSerialData.readline()
        print (myData.decode())

But I get error messages like this,

=========== RESTART: /Users/donaldlair/Documents/YoutubeARDTOPY.py ===========

Traceback (most recent call last):
  File "/Users/donaldlair/Documents/YoutubeARDTOPY.py", line 3, in <module>
    arduinoSerialData = serial.Serial('/dev/cu.usbmodem14101', 9600)
AttributeError: module 'serial' has no attribute 'Serial'

So I looked into my dir(serial) folder and this came out (I was told to do this, still not sure why but this might help to figure out.

>>> dir(serial)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'abc', 'absolute_import', 'division', 'errors', 'generators', 'hooks', 'marshal', 'meta', 'model', 'nested_scopes', 'print_function', 'properties', 'request', 'test', 'unicode_literals', 'utilities', 'with_statement']

Much of these things I just learned for the first time, so if you do answer which I appreciate, please dumb it down a bit as I am somewhat illiterate and a beginner.

Thank you!

gre_gor
  • 6,669
  • 9
  • 47
  • 52
  • 1
    `dir(serial)` should show a list of valid attributes of that module. COmparing with the output on my computer, there are many things missing in yours, one of them obviously, the Serial class. Maybe there is something else with the name serial that you are mistakenly importing. Could you try `serial.__file__`, `serial.__path__`, `serial.__cached__`. – Arthur Moraes Do Lago Jan 23 '19 at 12:51
  • Thank you. As I'm a beginner I want to make sure I understand. Do you mean instead of import serial #Import Serial Library arduinoSerialData = serial.Serial('/dev/cu.usbmodem14101', 9600) I should be import serial #Import Serial Library arduinoSerialData = serial.__file__('/dev/cu.usbmodem14101', 9600) for example? Thanks! – Donny Lair Jan 23 '19 at 15:09
  • No, just open a python console, do `import serial`, then `serial.__path__`, then `serial.__file__`, etc,etc... I just want you to check the value of these variables(that are inside the module serial). This will tell us where is this serial module coming from, and we will se if it is the right place. – Arthur Moraes Do Lago Jan 23 '19 at 15:17
  • Hey, I opened Python Shell 3.7.2 and ran import serial.__path__ etc but after about 4 I realized they all say something like this. I thought I was supposed to have these, so I figure I'm doing something wrong? Thanks! ============= RESTART: /Users/donaldlair/Documents/trystack2.py ============= Traceback (most recent call last): File "/Users/donaldlair/Documents/trystack2.py", line 2, in import serial.__file__ ModuleNotFoundError: No module named 'serial.__file__' – Donny Lair Jan 24 '19 at 11:22
  • First you run `import serial` to import the module, **not** `import serial.__path__`. Then after that, you run `serial.__path__` to check where it came from. These are two separate commands. – Arthur Moraes Do Lago Jan 24 '19 at 11:27
  • I put 1st line "import serial" and second line "run serial.__path__" etc. I noticed "run" doesn't become a color so I figured it's not an actual command so tried a variety of different things. In those variety of things I tried I got things such as "'list' object is not callable" back, and similar error messages. This may be a case that I am seriously too much of a beginner/idiot. I appreciate your help, this is probably frustrating for you and I don't blame ya if you don't want to help me anymore lol. – Donny Lair Jan 24 '19 at 12:18
  • You are doing these things on script,by the looks of it. If running from a script, do `import serial` on the first line and `print(serial.__path__)` in the first line if you are using python3 (`print serial.__path__` if using python2). What 's your setup for programming? What I suggested earlier related to going to a terminal, and typing `python`, this would open an interactive python console where you can type lines and execute them on-the-fly, it's usefull for these extremely short tests. – Arthur Moraes Do Lago Jan 24 '19 at 12:28
  • OK, I got it. Does this tell us much? >>> print (serial.__cached__) /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/serial/__pycache__/__init__.cpython-37.pyc , >>> print (serial.__file__) /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/serial/__init__.py , >>> print (serial.__path__) ['/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/serial'] – Donny Lair Jan 24 '19 at 12:45
  • Weird, this looks about right. Is this a different project you used to test this? If it is another one, please verify if `print(dir(serial))` still has the same output. I wanted to verify if you did not have any files/folders named serial in the project that is having problems... Check out this question: https://stackoverflow.com/questions/11403932/python-attributeerror-module-object-has-no-attribute-serial it's the same problem you are having, try some of the answers there(except the first one, don't think that can help). – Arthur Moraes Do Lago Jan 24 '19 at 13:26
  • Yes, print(dir(serial)) still comes up with exactly those files. I went to the link (thank you) and I tried all of the suggestions listed there that I could find. None of them seemed to work. I still get the error everytime AttributeError: module 'serial' has no attribute 'Serial'. I will keep trying different ways. Thanks again :) – Donny Lair Jan 24 '19 at 14:16

0 Answers0