Building PyQT5 with Python 2.7 on Ubuntu 16.04

So you want Qt5, but you have a lot of strict dependencies holding you back from going to Python 3. What to do? Go build everything yourself!

The following are steps based on a fresh install of Ubuntu 16.04, so adapt it per your needs.

First install the latest version of Qt. I was using the free open source edition. At the time of this post, the following was the set of commands given by Qt’s official website. I just downloaded the installation into my Downloads folder and ran it:

First download the installer:

Next, adjust the permissions and install Qt:

Now, that should have installed Qt5.x on your Ubuntu installation, it is time to install PyQt5 such that it uses Qt5 with Python 2.7. The key in this setup procedure is to build PyQt5 yourself.

First, SIP must be installed before proceeding with building PyQt5. You can download SIP from here. You can also just wget it!

Now is where things get important, as I always prefer to use virtual environments when working with Python, rather than installing everything on the global Python installation. After extracting the file, make sure to run configure.py using your virtual environment’s Python!

If the configuration was successful, the output should tell you that things related to SIP will be installed in your virtual environment’s folder, and NOT in your global Python that resides in /usr.

Now, running make and sudo make install will install SIP into your virtual environment folder, even if you are using sudo.

Now it is time to download PyQt5 and build it!

Configuration of PyQt5 is needed for building it. Again, using the right interpreter and the right parameters are key.

Now, assuming there are no errors, you should be able to run ‘import PyQt5’ in your virtual environment running Python 2.7!

Installing ZeroMQ & PyZMQ on Ubuntu

ZeroMQ is a distributed messaging system where a programmer of any level of expertise can easily connect their code across languages and platforms. Recently I had a need to connect multiple nodes on one of my projects and researched around until I found ZeroMQ. I took a quick glance on the Learn the Basics page and saw how easy it is to implement it myself and any of my team members to implement it.

In fact, the most difficult part with using ZeroMQ was the installation process and getting it to work with Python. PyZMQ is the Python binding for ZeroMQ, but I found the installation procedures a bit confusing and thought that I would give my own way of installing ZeroMQ and PyZMQ on Ubuntu.

This is assuming that you are installing on a new installation of Ubuntu. Some dependencies may already be installed if you are using a system that is already setup.

After installing some basic dependencies, we need to install libsodium. The following command lines are the way to install libsodium from source.

Now, we can finally install ZeroMQ!

Finally, on with PyZMQ, the Python binding for ZeroMQ.

Now, to test that PyZMQ was correctly installed, try:

If no errors show up, you are ready to go!

Since ZeroMQ and PyZMQ are constantly updated, I will try to keep this post updated with every major version.

Lua Classes

Lua and classes are a little awkward, as there really is no such thing as classes in Lua. However, it is possible to demonstrate a class like behavior using tables.

Tables are a type of object, and since an instance of a class is also an object, we can use tables as if the language itself supported classes.

You can see that an object called “Triangle” is created and useful functions for it is also created. If we were to execute these functions:

Then the outputs become:

Note that instead of the period ‘.’, I used the colon ‘:’ to create the functions. This is to pass ‘self’ as the first parameter for object-oriented programming. In the case that I used a period to create the functions, the following commands would result in an error.

In the entire reference manual, the colon syntax is mentioned very briefly, but personally, I find this to be a key syntax to effectively conduct OOP using Lua.

Python Trick of the Day (Sequence Types)

The thing that attracts me the most about programming is how you can make a certain code shorter by using clever logic or clever syntaxes. Through “Trick of the Day,” I can hopefully share a trick that I think is clever during my work (which involves quite a bit of programming).

Today’s trick is a very clever one in that if you have an instance such as the following:

There just has to be a way to shorten that repetition. Fortunately in Python, a trailing comma notation can be used to create a one-term tuple. This is called a sequence type.

So we could write the above code as:

I particularly find myself heavily using this when creating multiple objects of the same class and that requires the same inputs.

If you have any other way you perform this, feel free to share your thoughts below.

Lua Table Concatenation / Merge

Recently I had a need to concatenate a few tables in Lua and thought that it might be useful to share for those who may need to do something similar. A very simple three line function that can be expanded to accommodate even more tables as need be.