22. March 2014

Kivy – buildozer android debug failed with libstdc++.so.6: cannot open shared object file

Kivy is awesome library for developing GUI applications in Python.

It’s possible to build same application for desktop, Android or iOS. It’s something like Cordova/PhoneGap for JavaScript.

I was following Kivy crash course 2: Building an android apk tutorial recorded by Alexander Taylor.

I was trying to build application on Linux Debian for Android:

buildozer android debug

Build failed with quite strange message:

[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] Found 1 AIDL files.
     [aidl] Compiling 1 AIDL files.
     [aidl] /home/georgik/.buildozer/android/platform/android-sdk-21/platform-tools/aidl: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory


assets/private.mp3: /home/georgik/idea/kivytest/.buildozer/android/app/sitecustomize.pyo
Traceback (most recent call last):
  File "build.py", line 431, in 
  File "build.py", line 346, in make_package
    subprocess.check_call([ANT, arg])
  File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ant', 'debug']' returned non-zero exit status 1

The reason of this problem is not so obvious.

My operating system is 64bit, but Android build system requires 32 bit version of stdc++ library.

Fix is very easy. Just install lib32stdc++6 package :-)

apt-get install lib32stdc++6

If build is still failing, because of other missing libraries, then you can use online Debian package search to find missing dependencies: https://www.debian.org/distrib/packages

Other missing 32bit libraries are often libz, libncurses5:

apt-get install lib32z1 lib32ncurses5

29. June 2013

True/False gotcha Python vs Ruby vs PowerShell vs NodeJS vs PHP

Evaluation of conditions is very important part programming. True is ture, false is false…

Or not? It might surprise you, but not all languages evaluate numbers, empty strings or empty arrays in the same way.

Let’s examine several technologies. Python, Ruby, PowerShell, NodeJS and PHP.

Here is small code written in Python:

def test(value):
    if value:
        print "True"
        print "False"


Here is similar code written in Ruby:

def test(value)
    if value
        print "True"
        print "False"


Let’s compare it to PowerShell:

Function Test($value) {
    if ($value) {
        Write-Host "True"
    } else {
        Write-Host "False"


Same logic in JavaScript for NodeJS:

function test(value) {
    if (value) {
    } else {


Code in PHP:

function test($value) {
    if ($value) {
        echo "True";
    } else {
        echo "False";


Results are little bit surprising:


Python Ruby PowerShell NodeJS PHP
0 False True False  False False
1 True True True True True
“” False True False False False
[] False True True  True False
{} False True True  True False

2. June 2013

Configure Nginx with uWSGI to serve Pootle

It’s quite easy to set up Pootle. Just follow the manual – Quickstart.

virtualenv /var/www/pootle/env/
 source /var/www/pootle/env/bin/activate
 (env) $ pip install pootle
 (env) $ pootle init
 (env) $ pootle syncdb --noinput
 (env) $ pootle initdb

You can start Pootle with default CherryPy server. In order to boost performance it is necessary to use more powerfull server.

Let’s take intermediate step and serve Pootle by uWSGI.

First of all you’ll need to create wsgi.py file, because this file is missing in default Pootle installation. File: /var/www/pootle/wsgi.py

import os

# this part is only required when running from checkout instead of an install
    import sys
    ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
    sys.path.insert(0, ROOT_DIR) # Top level directory
    import syspath_override
except ImportError:
    # not running from checkout

# comment the above lines if running from install

os.environ['DJANGO_SETTINGS_MODULE'] = 'pootle.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

You can start uWSGI server by following command:

uwsgi --socket --chdir /var/www/pootle/lib/python2.7/site-packages/pootle --wsgi-file wsgi.py --master --virtualenv /var/www/pootle/ --http ":9090"

This will create uWSGI server and you can test it by connecting to http://localhost:9090

Let’s take further step and configure Nginx to server Pootle. We can modify previous command, because we do not need to server it as http at port 9090:

uwsgi --socket --chdir /var/www/pootle/lib/python2.7/site-packages/pootle --wsgi-file wsgi.py --master --virtualenv /var/www/pootle/

Create webroot directory where you will put static assets, just to avoid information leackage. Store there symlinks to assets and static files.

mkdir /var/www/pootle/webroot
ln -s /var/www/pootle/lib/python2.7/site-packages/pootle/assets /var/www/pootle/webroot/
ln -s /var/www/pootle/lib/python2.7/site-packages/pootle/static /var/www/pootle/webroot/

Store configuration to /etc/nginx/sites-available and create symlink to /etc/nginx/sites-enabled. Configuration of site:

upstream emperor {

server {
  listen 80;
  server_name pootle.sinusgear.com;
  root /var/www/pootle/webroot;

  access_log /var/log/nginx/pootle.sinusgear.com_access.log;
  error_log /var/log/nginx/pootle.sinusgear.com_error.log;

  location / {
    location ~* ^.+\.$ {
      root /var/www/pootle/webroot/static/styles;
      expires 30d;
    try_files $uri @django;

  location @django {
    root /var/www/pootle;
    include uwsgi_params;
    uwsgi_param UWSGI_FASTROUTER_KEY $host;
    uwsgi_pass emperor;

  location = /robots.txt {
    root /var/www/pootle/webroot/static/;
    access_log off;

  location ~* ^.+\.py$ {
    return 404;

Reload Nginx and Pootle should be much faster :)

I recommend book Mastering Nginx. You can learn there much more about Nginx configuration.

26. May 2013

Python virtualenv and PowerShell

It’s quite easy to set up virtual environment with isolated packages for Python in PowerShell.

Creating virtual environment is the same like in any other shell. Let’s call this environment pyenv:

pip install virtualenv
virtualenv pyenv

The last step is to activate this environment in PowerShell (watch dots and spaces):

. .\pyenv\Scripts\activate.ps1

You should see name of your virtual environment in command line. Virtual environment is active.

11. May 2013

Plone Error: There is a version conflict. We already have: distribute 0.6.38

I was trying to update one very old instance of Plone configured by buildout. Result of running ./bin/buildout was this error message:

  Loading extensions.
Error: There is a version conflict.
We already have: distribute 0.6.38

There was distribute package installed on system which caused conflict. The solution was to remove the package:

apt-get remove --purge python-zc.buildout

That leads to another error message that buildout script is outdated. Correction:

curl -O http://downloads.buildout.org/2/bootstrap.py
python bootstrap.py

There was another error after using latest version of buildout:

  Getting section instance.
  Initializing section instance.
  Installing recipe plone.recipe.zope2instance.
Error: There is a version conflict.
We already have: zope.interface 3.6.1

Solution was same as before. Just remove zope.interface package from system:

apt-get remove --purge python-zope.interface

After this small fix it was possible to run buildout without any problem.

Update: I encountered this issue again. This time it was necessary to delete develop-eggs directory and restart buildout again.