Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to use / import apigpio #13

Open
arthurlutz opened this issue Oct 5, 2019 · 4 comments · May be fixed by #14
Open

Failing to use / import apigpio #13

arthurlutz opened this issue Oct 5, 2019 · 4 comments · May be fixed by #14

Comments

@arthurlutz
Copy link

From missionpinball/mpf#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
Copy link
Contributor

jabdoa2 commented Oct 27, 2019

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).

@jabdoa2 jabdoa2 linked a pull request Oct 27, 2019 that will close this issue
@NNTin
Copy link

NNTin commented May 29, 2020

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
Copy link
Contributor

jabdoa2 commented May 29, 2020

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
Copy link
Contributor

jabdoa2 commented Jul 5, 2020

@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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants