How to install python-pcl pcl_visualization on Ubuntu

pcl_visualization is a handy visualization feature if you are mostly working with PCL’s PointT format. Unfortunately, for some reason, the visualizer cannot be installed with the provided setup.py file. Hence, you need to make some modifications to it to make it work with certain versions of VTK if you plan on using the visualizer on Ubuntu.

My setup is Ubuntu 16.04. Note that you may have to make some adjustments to the command lines if you are running a different version.

The idea is uncomment certain parts of the “setup.py” file and modify a line such that pcl_visualization runs using the VTK version you have installed on your machine.

In my version of python-pcl, I uncommented line 561:

Included above:

Note that I used “vtk-6.2” instead of “vtk-5.8” because that was the VTK available when I observed the directory contents in /usr/include/.

Lastly, I uncommencted line 625:

For reference purposes, I did not install PCL explicitly, but used the one that came default with ROS Kinetic.

Passing arguments to Python callback in rospy

To pass more arguments to your callback function in rospy, it is actually super simple.

Of course, rather than a tuple, something like a single “String” could also be passed directly.

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.

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.