Swift on Ubuntu on Google Cloud Compute

These are the steps to install Swift for Tensorflow on Google Cloud Compute.

Create Instance of Google Cloud Compute

  1. Go to https://console.cloud.google.com
  2. Create a new Project, say “swift-linux”.
  3. Go to “Compute Engine” from the top left menu, and choose VM instances.
  4. Click the icon “create instance”, and create Ubuntu 18.04 LTS instance.

Once it is created, you can access it using SSH.

Accessing Your Compute Instance

  1. From the Compute Engine -> VM instance, go to the line of your newly created VM instance, and find “SSH”. Click “view gcloud command”.
  2. Copy the gcloud command and run on the terminal. For example:
    $ gcloud compute --project "your project name" ssh --zone "your instance zone" "your instance name"
  3. If you have error on the zone or the project. Try to initialize gcloud configuration to the correct project and zone by running:
    $ gcloud init

Installing Swift Toolchain

The steps are described here: https://github.com/tensorflow/swift/blob/master/Installation.md

On your Ubuntu VM instance, do the following:

  1. Update your package manager
    $ sudo apt-get update
  2. Install the dependencies
    $ sudo apt-get install clang libpython-dev libblocksruntime-dev libatomic1 libicu-dev
  3. Download the latest release of the Toolchain from https://github.com/tensorflow/swift/blob/master/Installation.md
  4. If you need to copy the file from your computer to your instance, use the following command. Change the filename to the one you download.
    gcloud compute scp swift-tensorflow-RELEASE-0.3.1-ubuntu18.04.tar.gz  'ubuntu-swift':~/
  5. On your VM Instance, extract and copy somewhere where the PATH can find. In the code below, it is copied to
    $ cd
    $ tar xzvf swift-tensorflow-RELEASE-0.3.1-ubuntu18.04.tar.gz
    $ sudo cp -r usr /opt/
  6. Add the bin folder to your path:
    $ export PATH=/opt/usr/bin:$PATH
  7. You should be able to run swift and swiftc.
    $ swift
    $ swiftc



Jupyter notebook keeps on reconnecting to kernel because of tornado

Recently after I upgraded jupyter notebook on my anaconda distribution, it stops working. Every time it opens a python notebook, it keeps on showing “connecting to kernel” on the top right. The console shows the following error message:

[E 15:45:52.335 NotebookApp] Uncaught exception in /api/kernels/1633c355-600d-4653-b7fd-048fc1697007/channels
 Traceback (most recent call last):
 File "C:\Users\TABLET0006\Anaconda3\lib\site-packages\tornado\websocket.py", line 498, in _run_callback
 result = callback(*args, **kwargs)
 File "C:\Users\TABLET0006\Anaconda3\lib\site-packages\notebook\services\kernels\handlers.py", line 262, in open
 super(ZMQChannelsHandler, self).open()
 File "C:\Users\TABLET0006\Anaconda3\lib\site-packages\notebook\base\zmqhandlers.py", line 176, in open
 self.send_ping, self.ping_interval, io_loop=loop,
 TypeError: __init__() got an unexpected keyword argument 'io_loop'

I searched online, and found that tornado may cause the issues:


So I decided to downgrade tornado to 4.4.3 and it fixed my probem. To downgrade tornado. First, open Anaconda Prompt or your command prompt with python, and type the following:

pip install --ignore-installed tornado=4.4.3



Installing dbus on Mac OS using Brew

To install dbus, I follow the steps here: http://brewinstall.org/install-dbus-on-mac-with-brew/

  • First, open Terminal
  • Run the following command on the terminal:
  • ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
  • Then you need to install Xcode command line tools:

xcode-select –install

  • After that, run brew:

brew install dbus

Running Thymio Wireless with Python on Ubuntu Virtual Machine

I have written a post on running Thymio using Raspberry Pi. Somehow the wireless connection was not working for me even after I plug the usb wifi. So I decided to try using Ubuntu Virtual Machine on Windows host. And it works.


  • Host OS: Windows 10
  • VirtualBox
  • Virtual Machine OS: Ubuntu 16.04 LTS

After finish installing Ubuntu on the VirtualBox. These are the steps:

  1. Install aseba following the steps here. The official documentation provides steps for Ubuntu.
  2. Install dbus: sudo apt-get install python-dbus
  3. Install gobject: sudo apt-get install python-gobject

Now you can follow the steps to run the python code:

  1. run asebamedulla: sudo asebamedulla “ser:name=Thymio-II”
  2. run python code on a different terminal: sudo python pithymio.py

Running Python on Thymio

I found a link that describes the process here:


The setup that I use is Raspberry Pi 2 Model B+ running Jessie. First we need to setup the hardware connection:

  1. Connect USB from Pi to Thymio
  2. Connect power from socket to Pi
  3. Start Pi

Now, we need to install some software. There is a bug in the software provided by Thymio websites, so I found a forum where they provided the fix for Pi. On your pi, open terminal, and type the following:

sudo apt-get install apt-transport-https

This is to enable apt-get to get source from https.


Now, we add the source by editing /etc/apt/sources.list:

sudo sh -c 'echo "deb https://dl.bintray.com/msprunck/Aseba jessie main" | sudo tee -a /etc/apt/sources.list'
sudo apt-get update
sudo apt-get install libenki libdashel aseba

After it is installed, we can test if asebamedulla is running. To do this, open a new terminal, and type:

sudo asebamedulla "ser:name=Thymio-II"

If it works, it will output something like the following:

Found Thymio-II on port /dev/ttyACM0

Now, download the sample code. Open a new terminal or a new tab, and run the sample code as follows:

sudo python pithymio.py

It will output:

dbus.Array([dbus.STring(u'thymio-II')], signature=dbus.Signature('s'))
0 0 0 0 0

At this point, it waits for you to enter the command.

  • Type “w” and press Enter to move forward for 1 second.
  • Type “s” and press Enter to move backward for 1 second.
  • Type “a” to rotate to left
  • Type “d” to rotate to right

Type CTRL-C to exit.


Installing zenburn theme on Aquamacs

I followed the steps in https://github.com/bbatsov/zenburn-emacs to install zenburn theme using MELPA. But I had difficulty making it stick the next time it loads. These are the steps that works with me:

  1. Run Aquamacs
  2. Type: M-x package-install zenburn-theme
  3. I also added (load-theme ‘zenburn t) to “~/Library/Preferences/Aquamacs Emacs/Preferences.el”

But when I close and run Aquamacs again it is not exactly zenburn as the lower bar text are too dark. So I need to load the theme manually:

M-x load-theme zenburn

To make it stick, I follow the steps in: https://www.emacswiki.org/emacs/AquamacsFAQ#toc21

  1. With zenburn theme loaded, I go to: Menu -> Options → Appearance → Auto Faces → Use Current Face as Default
  2. And I do the next step: Menu → Options → Appearance → Adopt Face and Frame Parameters as Default
  3. Answer “Yes” to the dialog.
  4. Exit Aquamacs and “Y” to save the settings.

Multiple LDAP authentication in Django

Django allows multiple LDAP configuration. The example of the configuration is given here: https://pythonhosted.org/django-auth-ldap/multiconfig.html

To do this we need to create a Python module under site-packages. For example we can create a module called ‘mypackage’.

$ ls /home/administrator/websenv/lib/python2.7/site-packages/mypackage
__init__.py ldap.py

We can leave __init__.py empty, and write the following entry into ldap.py:

from django_auth_ldap.backend import LDAPBackend

class LDAPBackend1(LDAPBackend):

class LDAPBackend2(LDAPBackend):

class LDAPBackend3(LDAPBackend):

Now, we can configure the ldap in Django settings.py. This is an example of a configuration in Django.

import ldap
from django_auth_ldap.config import LDAPSearch


AUTH_LDAP_2_SERVER_URI = "ldap://student.myschool.edu.sg"
AUTH_LDAP_3_SERVER_URI = "ldap://stafff.myschool.edu.sg"
AUTH_LDAP_1_SERVER_URI = "ldap://"

AUTH_LDAP_2_USER_DN_TEMPLATE = "%(user)s@student.myschool.edu.sg"
AUTH_LDAP_3_USER_DN_TEMPLATE = "%(user)s@staff.myschool.edu.sg"
AUTH_LDAP_1_USER_DN_TEMPLATE = "%(user)s@myschool.edu.sg"


In the example above, we created three backends LDAP1, 2, and 3. We first import the backends to Django and set the URI, DN_TEMPLATE, and bind the domain.

We may need to restart Django and the server:

$python manage.py syncdb
$sudo apachectl restart