Python 3 on NAO
By default; NAO and Choregraphe work with Python 2. It’s possible to add Python 3 as an extra package, but note that it will not work in Choregraphe boxes, only in scripts (that can be used in Choregraphe projects to make Python 3 apps).
Installation
Having Python 3 on your NAO will require installing the python3nao package, which contains Python 3 as well as libraries such as qi
and numpy
. You will need an Aldebaran account to be able to install the packages.
Building applications
NAO Applications are very convenient, they can be linked to dialog, to webpages, they can be started and stopped via Choregraphe, they can be published to cloud.aldebaran.com.
Starting from a template
As a simple starting point, you can clone this example project:
You can also use cookiecutter to generate new projects from this template:
(this will be more convenient than going around changing the Application name and ID in various places in the project)
Building or adapting your own
If you want to build your own app, the important part is to include this line in your manifest.xml (adapting to your script):
<services>
<service execStart="/home/nao/.local/share/PackageManager/apps/python3nao/bin/runpy3.sh scripts/yourscript.py" name="yourappname" autorun="true"/>
</services>
You can use this to build apps and services; you can look at robot-jumpstarter project has some Python 2 templates that could be adapted.
Installing the app on NAO
You can open these projects with Choregraphe; however there is an issue (as of November 2030) whereby Choregraphe runs a linter on the code that excepts Python 2, and it might recognize some Python 3 syntax as “invalid” and not install the package.
As a workaround, you can install to the robot with qipkg, which you can install with pip install qipkg
.
qipkg deploy-package ./app/my_app.pml --url nao@nao.local
Note that this requires that your .pml file properly index all the files in your package.
Usage in command line
If you just want to do command-line usage without the whole application packaging, you can simply execute /home/nao/.local/share/PackageManager/apps/python3nao/bin/runpy3.sh
to get a python console, or pass your script to that (it can be worth creating a symbolic link).
API Reference
You can find the API reference in the official documentation (examples given are for Python 2, often with the older ALProxy-based approach), but the APIs work the same.
FAQ
Can I also use it on my computer?
Sure, you can do this without any extra package; just pip3 install qi
might work (depending of your environment), and if it doesn’t, rebuild libqi-python from source as explained there.
Why runpy3.sh?
On NAO, the PYTHONPATH
environment variable is set to include a folder containing the Python 2.7 version of the qi library; so if you just directly use the python3
in the package and do import qi
, it will find the Python 2.7 library first, and fail.
Isn’t Python 3 already installed on the system?
Yes, there is actually already a Python 3.5 installed on NAO, but it does not include qi
or naoqi
libraries and so cannot be used for controlling the robot.
Why doesn’t ALProxy work?
ALProxy is part of the deprecated naoqi
library that is not in the package; use the qi
library instead, it offers the same functionality (and more) with a slightly different syntax.