Search code examples
pythonarduinoattributeerrorpython-3.11pyfirmata

pyFirmata gives error: module 'inspect' has no attribute 'getargspec'


I'm trying to use pyFirmata, but I can't get it to work. Even the most basic of the library does not work. I guess there is something wrong with the library code.

from pyfirmata import Arduino,util
import time

port = 'COM5'
board = Arduino(port)

I get this error:

Traceback (most recent call last):
  File "c:\Users\Public\pythonpublic\arduino.py", line 5, in <module>
    board = Arduino(port)
            ^^^^^^^^^^^^^
  File "C:\Users\marce\AppData\Roaming\Python\Python311\site-packages\pyfirmata\__init__.py", line 19, in __init__      
    super(Arduino, self).__init__(*args, **kwargs)
  File "C:\Users\marce\AppData\Roaming\Python\Python311\site-packages\pyfirmata\pyfirmata.py", line 101, in __init__    
    self.setup_layout(layout)
  File "C:\Users\marce\AppData\Roaming\Python\Python311\site-packages\pyfirmata\pyfirmata.py", line 157, in setup_layout
    self._set_default_handlers()
  File "C:\Users\marce\AppData\Roaming\Python\Python311\site-packages\pyfirmata\pyfirmata.py", line 161, in _set_default_handlers
    self.add_cmd_handler(ANALOG_MESSAGE, self._handle_analog_message)
  File "C:\Users\marce\AppData\Roaming\Python\Python311\site-packages\pyfirmata\pyfirmata.py", line 185, in add_cmd_handler
    len_args = len(inspect.getargspec(func)[0])
                   ^^^^^^^^^^^^^^^^^^
AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'?

Solution

  • According to the first line of pyFirmata docs:

    It runs on Python 2.7, 3.6 and 3.7

    You are using Python 3.11. The inspect (core library module) has changed since Python 3.7.