ola api for python 3.x

1,172 views
Skip to first unread message

Stefan Krüger

unread,
Oct 31, 2016, 6:40:20 PM10/31/16
to open-lighting
Hi @all.

is it currently possible to use the api with python 3?
my first test was negative. (ola was only available in python 2)

sunny greetings
stefan

Stefan Krüger

unread,
Nov 1, 2016, 5:36:36 PM11/1/16
to open-lighting
Yeah - found the solution - it is possible -
i first had to install protobuf for python3:
stefan:/$ sudo -H pip3 install protobuf
[sudo] password for stefan:
Collecting protobuf
  Downloading protobuf-3.1.0.post1-py2.py3-none-any.whl (347kB)
    100% |████████████████████████████████| 348kB 1.3MB/
s
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/lib/python3/dist-packages (from protobuf)
Requirement already satisfied (use --upgrade to upgrade): six>=1.9 in /usr/lib/python3/dist-packages (from protobuf)
Installing collected packages: protobuf
Successfully installed protobuf-3.1.0.post1

then i only had to include the path to the ola/python directory in the python sys path..
for me this works:
stefan:/$ python3
Python 3.5.2 (default, Sep 10 2016, 08:21:44)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('/
home/stefan/ola/python')
>>> import ola
>>> from ola.ClientWrapper import ClientWrapper
>>>
>>> exit()
stefan:/$

until now i have not made any additional tests..
(they will follow tomorrow)

sunny greetings
stefan

Stefan Krüger

unread,
Nov 3, 2016, 10:23:36 AM11/3/16
to open-lighting
hi @all :-)
here are some news:
i have played around with python3 and the ola python examples:
stefan:~/ola/python/examples[master]$
stefan
:~/ola/python/examples[master]$ python3
Python 3.5.2 (default, Sep 10 2016, 08:21:44)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ola
Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>
ImportError: No module named 'ola'
>>>
stefan
:~/ola/python/examples[master]$ export PYTHONPATH="${PYTHONPATH}:/home/stefan/ola/python/"
stefan
:~/ola/python/examples[master]$ python3
Python 3.5.2 (default, Sep 10 2016, 08:21:44)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ola
>>> ola
<module 'ola' from '/home/stefan/ola/python/ola/__init__.py'>
>>>
stefan
:~/ola/python/examples[master]$

so basically its importing fine.

the basic send and receive examples are also working:
stefan:~/ola/python/examples[master]$ python3 ./ola_send_dmx.py
Success!
stefan
:~/ola/python/examples[master]$ python3 ./ola_recv_dmx.py
array
('B', [11, 50, 255])
array
('B', [13, 50, 255])
array
('B', [21, 50, 255])
array
('B', [25, 50, 255])
array
('B', [27, 50, 255])
array
('B', [30, 50, 255])
array
('B', [32, 50, 255])
array
('B', [34, 50, 255])
array
('B', [35, 50, 255])
array
('B', [37, 50, 255])
^CTraceback (most recent call last):
 
File "./ola_recv_dmx.py", line 66, in <module>
    main
()
 
File "./ola_recv_dmx.py", line 62, in main
    wrapper
.Run()
 
File "/home/stefan/ola/python/ola/ClientWrapper.py", line 278, in Run
   
self._ss.Run()
 
File "/home/stefan/ola/python/ola/ClientWrapper.py", line 195, in Run
    sleep_time
)
KeyboardInterrupt
stefan
:~/ola/python/examples[master]$

if i try the simple fade example this does not work:
stefan:~/ola/python/examples[master]$ python3 ./ola_simple_fade.py
Traceback (most recent call last):
 
File "./ola_simple_fade.py", line 69, in <module>
    wrapper
.AddEvent(SHUTDOWN_INTERVAL, wrapper.Stop)
 
File "/home/stefan/ola/python/ola/ClientWrapper.py", line 287, in AddEvent
   
self._ss.AddEvent(time_in_ms, callback)
 
File "/home/stefan/ola/python/ola/ClientWrapper.py", line 215, in AddEvent
    heapq
.heappush(self._events, event)
TypeError: unorderable types: _Event() < _Event()
stefan
:~/ola/python/examples[master]$

seems that in the heapq things something has changed.. (in python2 it just works..)

has someone of you an idea what could cause this? or iam on the wrong track with my way of using the lib from the git clone directly?!

sunny greetings stefan

Stefan Krüger

unread,
Nov 3, 2016, 6:43:15 PM11/3/16
to open-lighting
some update:
if i use my ola-threaded wrapper i get some additional execptions if i try to stop the wrapper:
stefan:~/xxxxx/ola[OLANode !]$ python3
Python 3.5.2 (default, Sep 10 2016, 08:21:44)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import olathreaded
>>> x = olathreaded.OLAThread()
>>> x.start_connection()
start_connection
run
self.state: OLAThread_States.waiting
waiting
for olad....
>>> get client
run ola wrapper
.

>>> x.stop_connection()
stop ola wrapper
.

Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>

 
File "/home/stefan/xxxxx/ola/olathreaded.py", line 242, in stop_connection
   
self.wrapper.Stop()
 
File "/home/stefan/ola/python/ola/ClientWrapper.py", line 266, in Stop
   
self._ss.Terminate()
 
File "/home/stefan/ola/python/ola/ClientWrapper.py", line 114, in Terminate
   
self.Execute(self._Stop)
 
File "/home/stefan/ola/python/ola/ClientWrapper.py", line 106, in Execute
    os
.write(self._local_socket[1], 'a')
TypeError: a bytes-like object is required, not 'str'
>>> exit()

^CException ignored in: <module 'threading' from '/usr/lib/python3.5/threading.py'>

Traceback (most recent call last):

 
File "/usr/lib/python3.5/threading.py", line 1288, in _shutdown
    t
.join()
 
File "/usr/lib/python3.5/threading.py", line 1054, in join
   
self._wait_for_tstate_lock()
 
File "/usr/lib/python3.5/threading.py", line 1070, in _wait_for_tstate_lock
   
elif lock.acquire(block, timeout):
KeyboardInterrupt
stefan
:~/xxxxx/ola[OLANode !]$

the used python file is at https://github.com/s-light/animation_nodes/blob/OLANode/nodes/ola/olathreaded.py

if i modify the ClientWrapper.py with this: (line 106)
os.write(self._local_socket[1], b'a')
the exception vanishes.
but somehow my thread never joins..
stefan:~/xxxxx/ola[OLANode !]$ export PYTHONPATH=$PYTHONPATH:/home/stefan/ola/python/
stefan
:~/xxxxx/ola[OLANode !]$ python3
Python 3.5.2 (default, Sep 10 2016, 08:21:44)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import olathreaded
>>> x = olathreaded.OLAThread()
>>> x.start_connection()
start_connection
run
self.state: OLAThread_States.waiting
waiting
for olad....
>>> get client
run ola wrapper
.

>>> x.stop_connection()
stop ola wrapper
.
join thread
:


^CTraceback (most recent call last):

 
File "<stdin>", line 1, in <module>

 
File "/home/stefan/xxxxx/ola/olathreaded.py", line 246, in stop_connection
   
self.join()
 
File "/usr/lib/python3.5/threading.py", line 1054, in join
   
self._wait_for_tstate_lock()
 
File "/usr/lib/python3.5/threading.py", line 1070, in _wait_for_tstate_lock
   
elif lock.acquire(block, timeout):
KeyboardInterrupt
>>>

^CException ignored in: <module 'threading' from '/usr/lib/python3.5/threading.py'>

Traceback (most recent call last):

 
File "/usr/lib/python3.5/threading.py", line 1288, in _shutdown
    t
.join()
 
File "/usr/lib/python3.5/threading.py", line 1054, in join
   
self._wait_for_tstate_lock()
 
File "/usr/lib/python3.5/threading.py", line 1070, in _wait_for_tstate_lock
   
elif lock.acquire(block, timeout):
KeyboardInterrupt
stefan
:~/xxxxx/ola[OLANode !]$

i have to dig some deeper

if someone of you have an idea / info let me know...

sunny greetings
stefan

headsonstage

unread,
Sep 16, 2017, 5:07:47 PM9/16/17
to open-lighting
Hi Stefan
Did you get this working?
I am trying very hard to get OLA API to work with Python3 on Raspberry Pi 3B.
regards

Cass M

unread,
Sep 18, 2017, 8:30:56 PM9/18/17
to open-lighting
Hi all,

My turn to jump in desperate for information. Did either of you manage to either get any further, or determine that this was impossible?

-Cass

Peter Newman

unread,
Sep 18, 2017, 8:50:50 PM9/18/17
to open-lighting
Hi Cass,

What errors do you get in Python when you try and use it?

Stefan Krüger

unread,
Sep 19, 2017, 1:15:13 PM9/19/17
to open-lighting
Hi @all,

if i remember correctly i get it working partly as i mentioned earlier with this hack...

back then this was good enough for my test things...

so no news from my side regarding this.

sunny greetings stefan

Josh Peterson

unread,
Oct 25, 2018, 9:32:04 AM10/25/18
to open-lighting
Adding more info:

The error I'm getting when I run my script is ImportError: No module named 'ola'

I've tried: sudo /etc/init.d/olad start

Josh Peterson

unread,
Oct 25, 2018, 9:32:04 AM10/25/18
to open-lighting
I need to use python3, and I'm trying to get this working on a raspberry pi 3B+. 

I've done sudo apt-get install ola ola-python

I'm now looking to append to the path like above, but what should the path for 'ola/python' be for rpi? I don't see it in /etc/ola


On Tuesday, September 19, 2017 at 1:15:13 PM UTC-4, Stefan Krüger wrote:

Peter Newman

unread,
Oct 25, 2018, 11:22:16 AM10/25/18
to open-lighting
Hi Stefan,

It seems I missed this a long time ago. To fix the heap ordering issue, we need to implement all the new ordering functions:

Or one and functools.total_ordering:

It looks like we may need to implement __hash__ too (which can just be the hash of _run_at I think):

Do you fancy having a go at that given you've done previous Python 3 work?

Peter Newman

unread,
Oct 25, 2018, 11:27:46 AM10/25/18
to open-lighting
See also this change regarding total_ordering:

Peter Newman

unread,
Oct 25, 2018, 11:30:43 AM10/25/18
to open-lighting
Hi Josh,

You can see where the files go here:

I.e. /usr/lib/python2.7/dist-packages/

You probably don't want to add all of that dist-packages to your Python 3 path, as I suspect bad things will happen. I imagine a symlink will be a better bet. We'll also look at trying to get some Python 3 packages made in future.

Stefan Krüger

unread,
Oct 25, 2018, 3:37:38 PM10/25/18
to open-lighting
Hi Peter,

i would like to take this as challenge!
but i don't know when i will find time for this..  (currently i think earliest in about four weeks or so..)
so if anyone else wants to do it please do it ;-)

is there already a tracking bug for this?

your linked pull request is indeed a good reference.
do we (have to) support python 2.6?

sunny greetings
stefan

Peter Newman

unread,
Oct 27, 2018, 6:00:32 AM10/27/18
to open-lighting
Hi Stefan,

Great, yeah go for it, unless as you say someone beats you to it. I've just raised this issue, as I couldn't see an existing one:

I'm hoping whoever takes on that will give the whole system a bit of a shakedown on Python 3 and fix any further remaining bugs.

Given it seems to be a fairly easy task to keep Python 2.6 in this case, and I believe we do currently (as recent changes have been asked to stay compatible), I'd like to for the 0.10 and soon to be release as 0.11 master branches, as they effectively should be as far as I'm aware. I need to do some more breaking changes soon for E1.33, which will go into what becomes the new master branch, at which point I'd say anything goes subject to Ubuntu LTS support (5 years). Someone else was asking about something recently too in C++ land, but I can't remember off hand what it was (possibly C++11 compatibility/dropping C++98).
Reply all
Reply to author
Forward
0 new messages