User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Installing OSC

Thu Feb 16, 2017 11:38 am

I have been trying to install PyOSC but without success. The method here viewtopic.php?f=91&t=59714 no longer works and the method here https://ianshelanskey.com/2014/08/11/ra ... sc-part-1/ doesn't either.
for example

Code: Select all

sudo ./setup.py install
returns " ./setup.py " no such command.
Running the latest Pixel desktop.
Any ideas?
Thanks

User avatar
paddyg
Posts: 2416
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Installing OSC

Tue Feb 21, 2017 11:40 pm

Mike, it looks as though you should download from git using clone, cd into the new dir, then install it by running the setup.py python program. The easiest way to run python programs (in my book) is to just add the file name and other arguments after 'python' i.e.
$ cd pyosc
$ sudo python setup.py install

Alternatively, as pyosc claims to be 'pure' python, you could add the path to the cloned repository in your python programs.

Code: Select all

...
import sys
sys.path.insert(1, '/home/pi/pyosc')
import pyOSC
...
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Installing OSC

Thu Feb 23, 2017 11:57 am

Thanks.
However I get the "no commands supplied error" when I do.

User avatar
paddyg
Posts: 2416
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Installing OSC

Thu Feb 23, 2017 1:18 pm

Hmm, what happens with the path.insert() method?
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Installing OSC

Thu Feb 23, 2017 1:53 pm

That seems to work except I have to do

Code: Select all

import sys
sys.path.insert(1, '/home/pi/pyosc')
import OSC
But I have not had time to actually send any OSC messages yet, I will try that later this afternoon.
Thanks

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Installing OSC

Thu Feb 23, 2017 9:35 pm

Well ...
I found out I could send OSC messages but it was no dice with receiving. I got the following error message:-

Code: Select all

Traceback (most recent call last):
  File "/home/pi/MagPi_projects/Osc/oscRX.py", line 21, in <module>
    s = OSC.OSCServer(receive_address) # basic
  File "/home/pi/pyosc/OSC.py", line 1765, in __init__
    UDPServer.__init__(self, server_address, self.RequestHandlerClass)
  File "/usr/lib/python2.7/SocketServer.py", line 420, in __init__
    self.server_bind()
  File "/usr/lib/python2.7/SocketServer.py", line 434, in server_bind
    self.socket.bind(self.server_address)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 99] Cannot assign requested address
I tried changing the IP address to 0.0.0.0 as suggested from sites on searching for that error, that actually worked in that there was no error but not surprisingly did not receive any OSC messages.

So I thought I would try another package, so I tried python-osc and got:-

Code: Select all

pi@raspberrypi:~ $ sudo pip install python-osc
Downloading/unpacking python-osc
  Downloading python-osc-1.6.2.tar.gz
  Running setup.py (path:/tmp/pip-build-qwJM4s/python-osc/setup.py) egg_info for package python-osc
    
Installing collected packages: python-osc
  Running setup.py install for python-osc
      File "/usr/local/lib/python2.7/dist-packages/pythonosc/dispatcher.py", line 53
        yield from handlers
                 ^
    SyntaxError: invalid syntax
    
    
Successfully installed python-osc
Cleaning up...

Clearly they are using "Successful" in a meaning that I have been hitherto unaware because on :-
import pythonosc
I got module not found.

Any idea of an OSC package that actually works?

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: Installing OSC

Thu Feb 23, 2017 10:23 pm

Code: Select all

pi@raspberrypi:~ $ sudo -H pip3 install python-osc
Downloading/unpacking python-osc
  Downloading python-osc-1.6.2.tar.gz
  Running setup.py (path:/tmp/pip-build-58bamgcn/python-osc/setup.py) egg_info for package python-osc
    
Installing collected packages: python-osc
  Running setup.py install for python-osc
    
Successfully installed python-osc
Cleaning up...

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Installing OSC

Fri Feb 24, 2017 7:37 am

Thank you ktb that did install correctly all be it only on a second attempt. Any idea why the official page https://pypi.python.org/pypi/python-osc has the installation instructions wrong?

However I am back to the same problem as before, the send works but the receive doesn't. Trying the simple server example code I get this error message:-

Code: Select all

Traceback (most recent call last):
  File "/home/pi/MagPi_projects/Osc/py3SimpleServer.py", line 35, in <module>
    (args.ip, args.port), dispatcher)
  File "/usr/local/lib/python3.4/dist-packages/pythonosc/osc_server.py", line 106, in __init__
    super().__init__(server_address, _UDPHandler)
  File "/usr/lib/python3.4/socketserver.py", line 429, in __init__
    self.server_bind()
  File "/usr/lib/python3.4/socketserver.py", line 440, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 99] Cannot assign requested address


This is after editing the IP and port address to match my device 192.168.1.67 - I can ping that device and can also send OSC to it (on a different port number of course). I get that error when setting up many address in the 192 domain. If I change the address to 127.0.0.1 then the code works but as their is nothing sending on that it is not much use. This is the same sort of error I was getting with the PyOSC module I tried at first. Is there something odd about the module that it won't work on the IP address I have, or what?
Thanks for your continued interest.

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: Installing OSC

Fri Feb 24, 2017 8:08 am

Hey Mike,

I'm not sure exactly why the page provides those instructions, but perhaps they are expecting for python 3 to be default. As far as I'm aware, some distros have moved on or are in the process of moving things to python 3 by default. The page does state "Open Sound Control server and client implementations in pure python (3.4+)." The developers have sort of addressed this problem at least a few times in the Issues section of their GitHub repo. This link provides some good explanations and information: http://askubuntu.com/questions/777085/w ... hon-binary

I've never used python-osc and honestly don't even understand what it is useful for. What devices are involved in your setup? If you provide a good explanation and give me some time, I'll try it myself provided I don't need any additional special devices/equipment.

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Installing OSC

Fri Feb 24, 2017 8:32 am

Thanks for the offer of help:-
provided I don't need any additional special devices/equipment.
Ah, as Shakespeare said "There's the rub".
The device I am using is an iPad running TouchOSC, it allows you to build interface screens on the iPad and send and receive OSC messages. I have used this many times with the Processing language running on a Mac, and I even have a chapter on OSC in my Arduino book http://www.apress.com/9781484217207, so I am quite familiar with OSC messages and how the whole thing works. I wanted to make some projects using Python on the Pi. As I said the OSC send works, and I can sent messages to change the display on my iPad but I can't get anything back from the iPad. It seems that either OSC receiving does not work "at the moment", which I have found is not a totally unknown thing in the Linux world, or there is something about the IP address / server / port / network setup that I am not fully understanding.

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: Installing OSC

Fri Feb 24, 2017 9:01 am

Interesting. I do happen to have an old iPad mini A1455 (Somebody gave it to me with a cracked screen, but it works fine). The only thing that's stopping me is that I'm not interested in buying the app (even though it does look rather cool). I suppose I have a 5th gen. iPod Touch some place around here too.

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Installing OSC

Fri Feb 24, 2017 10:29 am

Thanks, their are some free OSC apps for the iPad although the app store does not seem to be searching capable at the moment. However, the problem is before you actually get to communicate with the iPad. It boils down to that error message being given for any IP address except one that starts 127, as my network is on 192 it throws the error before it starts listening, so some insight as to why this is with the "Simple server" example code would be good to know.

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: Installing OSC

Fri Feb 24, 2017 10:57 am

Ah, I think I understand. So, maybe I can reproduce the problem without the iOS app. I'll give it a shot, might take me a while before I get to it.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Installing OSC

Fri Feb 24, 2017 12:19 pm

Grumpy Mike wrote:Well ...
I found out I could send OSC messages but it was no dice with receiving. I got the following error message:-

Code: Select all

Traceback (most recent call last):
  File "/home/pi/MagPi_projects/Osc/oscRX.py", line 21, in <module>
    s = OSC.OSCServer(receive_address) # basic
  File "/home/pi/pyosc/OSC.py", line 1765, in __init__
    UDPServer.__init__(self, server_address, self.RequestHandlerClass)
  File "/usr/lib/python2.7/SocketServer.py", line 420, in __init__
    self.server_bind()
  File "/usr/lib/python2.7/SocketServer.py", line 434, in server_bind
    self.socket.bind(self.server_address)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 99] Cannot assign requested address
I tried changing the IP address to 0.0.0.0 as suggested from sites on searching for that error, that actually worked in that there was no error but not surprisingly did not receive any OSC messages.

So I thought I would try another package, so I tried python-osc and got:-

Code: Select all

pi@raspberrypi:~ $ sudo pip install python-osc
Downloading/unpacking python-osc
  Downloading python-osc-1.6.2.tar.gz
  Running setup.py (path:/tmp/pip-build-qwJM4s/python-osc/setup.py) egg_info for package python-osc
    
Installing collected packages: python-osc
  Running setup.py install for python-osc
      File "/usr/local/lib/python2.7/dist-packages/pythonosc/dispatcher.py", line 53
        yield from handlers
                 ^
    SyntaxError: invalid syntax
    
    
Successfully installed python-osc
Cleaning up...
That "yield from" language was only introduced in python 3.3 so I don't think it should be in the python 2.7 package.

In python 2.7 that would, I think, be rewritten as:

Code: Select all

for handle in handlers:
    yield handle
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Installing OSC

Fri Feb 24, 2017 8:25 pm

Hi elParaguayo , thanks for your input. Yes it looked like it was installed for Python 2, but then as the module was written for Python 3 then it would not run because of syntax errors in the module. Luckily I have it installed under Python 3 now.

The main problem I am having now is that the module won't let me set the IP address for the domain I have my OSC device and network on. I don't know if this is a problem with the module or settings on the Pi. But given that two modules don't allow the setting of the IP address I want I am wondering if network things are different in the Linux / Pi world as opposed to the Unix / Mac world I am used to.
Thanks for your interest.

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Installing OSC

Fri Feb 24, 2017 11:51 pm

Small breakthrough, I got pyosc to work on receive. Basically, unlike the Mac, when the Pi is receiving OSC messages you have to set the IP address, not to the address of the device sending the OSC to you, but to the IP address of the Pi itself. By doing that I could get pyosc to receive OS messages. :D

Trying that trick on python-osc-1.6.2 still did not result in anything being printed but it also did not produce the error messages I was getting with the iPad's IP address so it was a bit of progress.
So I think I will proceed down the pyosc and Python 2 route for the moment but it would have been good if the Python 3 stuff worked.

With hindsight there was a cryptic clue in the example receiving code. It had the IP address set at 127.0.0.1 which means "yourself" so meaning "put your own IP address here". Then, just to confuse you, the same IP address was in the example send code and you do have to change that to the IP address of the device you are sending it to. Cunning these Python folk. :roll:

Thanks to all who have contributed.

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: Installing OSC

Sat Feb 25, 2017 2:15 am

Hi Mike,

It's good to see you've made some progress. Nice work! I did suspect the localhost IP addresses were part of the problem, but didn't want to recommend anything specific until I had a chance to play with it and understand how it should work. I still plan on playing around with this, but in light of your progress I think I'll focus on Python 3 with python-osc.

You're welcome.

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: Installing OSC

Sat Feb 25, 2017 10:48 pm

python-osc 1.6.3

It seems to work fine. Let me know if you have any questions.

Client: Mac Mini with Ubuntu 17.04
------------------------------------------------

Code: Select all

ktb@KTBMacMini:~/software/python$ ls -l
total 4
-rwxr-xr-x 1 ktb ktb 902 Feb 25 16:35 python-osc-simple-client.py
~/software/python/python-osc-simple-client.py:

Code: Select all

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Small example OSC client

This program sends 10 random values between 0.0 and 1.0 to the /filter address,
waiting for 1 seconds between each value.
"""
import argparse
import random
import time

from pythonosc import osc_message_builder
from pythonosc import udp_client


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--ip",
        default="192.168.1.36",
        help="The IP address of the OSC server (RPi3B)"
    )
    parser.add_argument(
        "--port",
        type=int,
        default=5005,
        help="The port the OSC server is listening on"
    )
    args = parser.parse_args()

    client = udp_client.SimpleUDPClient(args.ip, args.port)

    for x in range(10):
        client.send_message("/filter", random.random())
        time.sleep(1)

Server: Raspberry Pi 3 B with Raspbian Jessie
----------------------------------------------------------------

Code: Select all

pi@raspberrypi:~/software/python $ ls -l
total 4
-rwxr-xr-x 1 pi pi 1334 Feb 25 16:40 python-osc-simple-server.py
~/software/python/python-osc-simple-server.py:

Code: Select all

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Small example OSC server

This program listens to several addresses, and prints some information about
received packets.
"""
import argparse
import math

from pythonosc import dispatcher
from pythonosc import osc_server


def print_volume_handler(unused_addr, args, volume):
    print("[{0}] ~ {1}".format(args[0], volume))


def print_compute_handler(unused_addr, args, volume):
    try:
        print("[{0}] ~ {1}".format(args[0], args[1](volume)))
    except ValueError:
        pass

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--ip",
        default="192.168.1.36",
        help="The IP to listen on (RPi3B)"
    )
    parser.add_argument(
        "--port",
        type=int,
        default=5005,
        help="The port to listen on"
    )
    args = parser.parse_args()

    dispatcher = dispatcher.Dispatcher()
    dispatcher.map("/filter", print)
    dispatcher.map("/volume", print_volume_handler, "Volume")
    dispatcher.map("/logvolume", print_compute_handler, "Log volume", math.log)

    server = osc_server.ThreadingOSCUDPServer(
        (args.ip, args.port),
        dispatcher
    )
    print("Serving on {}".format(server.server_address))
    server.serve_forever()

Running it:
---------------
RPi3B:

Code: Select all

pi@raspberrypi:~/software/python $ ./python-osc-simple-server.py
Serving on ('192.168.1.36', 5005)
Mac Mini:

Code: Select all

ktb@KTBMacMini:~/software/python$ ./python-osc-simple-client.py
RPi3B:

Code: Select all

pi@raspberrypi:~/software/python $ ./python-osc-simple-server.py
Serving on ('192.168.1.36', 5005)
/filter 0.5342345833778381
/filter 0.8430014252662659
/filter 0.8018408417701721
/filter 0.14335119724273682
/filter 0.8951894044876099
/filter 0.7283394932746887
/filter 0.5045074224472046
/filter 0.18418659269809723
/filter 0.5337874889373779
/filter 0.07820449024438858


User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Installing OSC

Tue Mar 14, 2017 11:06 pm

Hi ktb,
Thanks for that it is great.
Sorry for not responding sooner but I did not get the email that said you had replied. I was going to do an update on what I found when using pyosc. I got it working sort of but it was a bit crap. Basically I am moving graphics around the screen with the OSC messages. I got it going using pyosc but it was not very good. Sometimes it would work smoothly and then there would be a delay of about 3 seconds before anything would move. Then it went into a weird mode where every OSC command played back slowly with about a 20 second delay. So it is not very good.

Anyway inspired by what I just saw you had done, I had a go this afternoon at python-osc 1.6.3 and did get it to respond to the messages by modifying the sample server code. Great I thought, and added this basic stuff to my program only to find that the OSC commands were not changing my variables in my application. I think what is happening is that the server is running in a separate thread to my other code. Sadly I don't know much about threads in Python.

As I see it I can either send variables across threads, if that is possible, or from examining the source code ( I can't seem to find any documentation ) run the server as Forking or as AsyncIO.
Unfortunately I don't know what either of these mean, how to do it and if once I have done it pass the values received to my Python Pygame program.

Is this something you could advise on?
Thanks

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: Installing OSC

Wed Mar 15, 2017 11:07 pm

I have some experience with Python threading from writing a hacky driver for an aluminum Apple Remote I have.

I don't want to make any promises, but if you share your code here or some place like GitHub, then I may play around with it when I have some time.

BTW, I did try playing around with some of the free OSC iOS apps. I don't have anything positive to say about them. :)

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Installing OSC

Thu Mar 16, 2017 11:31 am

Thanks for the offer but unfortunately I have a deadline fast approaching for this so I am going to have to switch tack, and move over from Python to Processing. It has a much simpler, and it seems more reliable, interface to OSC than Python. It also allows partial matching of the OSC message so you don't have to create a call back function for every OSC object in the Touch OSC interface. Mind you Python might offer that but I have not seen it yet.

I would like to get OSC working on Python but judging by the lack of example software on line I guess others found it too tricky as well, or maybe they just haven't been there yet.
I did try playing around with some of the free OSC iOS apps. I don't have anything positive to say about them
:D Yes I guess it is a case of you get what you pay for.

Thanks to everyone for all the help, I will have to crack this when I haven't got any deadline pressures.

robjharrison
Posts: 19
Joined: Tue Sep 05, 2017 6:48 am

Re: Installing OSC

Mon Sep 18, 2017 2:02 pm

AM i missing something if the below is not happening in python 3.5, Pi3
All I'm after is this module but the time it's taken searching for a solution to the no distribution found' is daft. I'm sure it's possible as ive had the script that i use the osc module in working on another device with the same card image, although that was several weeks back so i'm wondering what i've forgotten/missed. i need the udp_client and osc_message_builder

I've also tried sudo apt-get install python-osc
ktb wrote:
Thu Feb 23, 2017 10:23 pm

Code: Select all

pi@raspberrypi:~ $ sudo -H pip3 install python-osc
Downloading/unpacking python-osc
 <snip>
Successfully installed python-osc

rbn
Posts: 143
Joined: Tue Dec 27, 2011 8:32 pm
Location: Near Peterborough
Contact: Website

Re: Installing OSC

Sat Aug 18, 2018 12:43 pm

I can across this OLD thread and wondered if you were now functioning OK with OSC on a Pi. I use python-osc a lot with the Pi, to communicate with Sonic Pi 3 which has good support for both sending and receiving OSC.

here are some project writeup I have done which all make use of hit, some for just sending OSC messages, some for just receiving and some for both.

https://rbnrpi.wordpress.com/sonic-pi-3 ... y-pi-gpio/

https://rbnrpi.wordpress.com/2017/07/31 ... ontroller/

https://rbnrpi.wordpress.com/new-sonic- ... er-sensor/

https://rbnrpi.wordpress.com/a-touchosc ... r-sonicpi/

Return to “Python”