PierreRust / apigpio

apigpio - an asyncio-based python client for pigpio
MIT License
19 stars 11 forks source link

Failing to use / import apigpio #13

Open arthurlutz opened 4 years ago

arthurlutz commented 4 years ago

From https://github.com/missionpinball/mpf/issues/1427

File "/usr/local/lib/python3.7/dist-packages/mpf/core/machine.py", line 212, in initialise
    yield from self.initialise_core_and_hardware()
  File "/usr/local/lib/python3.7/dist-packages/mpf/core/machine.py", line 197, in initialise_core_and_hardware
    self._load_hardware_platforms()
  File "/usr/local/lib/python3.7/dist-packages/mpf/core/machine.py", line 497, in _load_hardware_platforms
    self.add_platform(hardware_platform)
  File "/usr/local/lib/python3.7/dist-packages/mpf/core/machine.py", line 614, in add_platform
    hardware_platform = Util.string_to_class(self.config['mpf']['platforms'][name])
  File "/usr/local/lib/python3.7/dist-packages/mpf/core/utility_functions.py", line 588, in string_to_class
    m = __import__(module)
  File "/usr/local/lib/python3.7/dist-packages/mpf/platforms/rpi/rpi.py", line 20, in <module>
    import apigpio
  File "/usr/local/lib/python3.7/dist-packages/apigpio/__init__.py", line 2, in <module>
    from .apigpio import Pi

I then go on to try to import apigpio from python2 and python3 and get :

pi@pizerow:~/mpf $ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import apigpio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/apigpio/__init__.py", line 2, in <module>
    from .apigpio import Pi
  File "/usr/local/lib/python3.7/dist-packages/apigpio/apigpio.py", line 390
    asyncio.async(self._wait_for_notif())
                ^
SyntaxError: invalid syntax
>>> 
pi@pizerow:~/mpf $ python
Python 2.7.16 (default, Apr  6 2019, 01:42:57) 
[GCC 8.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import apigpio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/apigpio/__init__.py", line 2, in <module>
    from .apigpio import Pi
  File "/usr/local/lib/python2.7/dist-packages/apigpio/apigpio.py", line 388
    yield from self._loop.sock_connect(self.s, address)
             ^
SyntaxError: invalid syntax
>>> 

Seeing from .apigpio import Pi I was looking for a Pi.py in /usr/local/lib/python3.7/dist-packages/apigpio/ but couldn't fit it :

ls /usr/local/lib/python3.7/dist-packages/apigpio/
__init__.py  __pycache__  apigpio.py  ctes.py  utils.py
ls /usr/local/lib/python2.7/dist-packages/apigpio/
__init__.py  __init__.pyc  apigpio.py  ctes.py  ctes.pyc  utils.py  utils.pyc
jabdoa2 commented 4 years ago

async and await are now reserved keywords in Python 3.7: https://docs.python.org/3/whatsnew/3.7.html#summary-release-highlights. Afaik asyncio.ensure_future is the new method to use (does not work in early 3.4 but that is EOL anyway).

NNTin commented 4 years ago

The PR does not work for me.

https://github.com/jabdoa2/apigpio/blob/patch-1/apigpio/apigpio.py#L475

self._loop.sock_sendall(self.s, data) is a coroutine, see:

https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.sock_sendall

It needs a yield from.

image

My gpio_test.py had the content of https://github.com/PierreRust/apigpio/blob/master/samples/gpio_write.py

jabdoa2 commented 4 years ago

We moved to a different repository for our fork: https://github.com/missionpinball/apigpio

We also publish it as apigpio-mpf

Will look into your comment to see if it also affects that repo.

jabdoa2 commented 4 years ago

@NNTin have a look at our maintained fork: https://github.com/missionpinball/apigpio. We also ship that to pypi: https://pypi.org/project/apigpio-mpf/