Setup PyQt4 in Houdini 13 for GUI Development

Posted: July 26, 2014 in FX Pipeline, Houdini, Linux, Uncategorized

qt-mainh13

In this post we start PyQt user interface widget toolkit to create a custom user interface inside Houdini.
Houdini does not distribute PyQt4, so if it is not installed you need to install it to your Python distribution.

Lets See How to install and setup Qt and PyQt4 in Linux Centos.

Check Houdini Python Paths
Run in your Terminal- env | grep houdini

Now Understand about python versions-
Centos 6.5 ship with python 2.6
and houdini 13 ship with python 2.6 and python 2.7
so if you have working python version installed in computer than houdini takes system python version.
else houdini will use HFS python versions.

to use Houdini Python versions
You can set HOUDINI_USE_HFS_PYTHON to 1 in houdini environment.
open file /home/rajiv/houdini13.0/houdini.env
add following line:
HOUDINI_USE_HFS_PYTHON = 1

Now you can see python2.7.5 in python shell of houdini.
but no PyQt4 modules for houdini.

Python 2.7.5 (default, Oct 24 2013, 12:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Houdini 13.0.481 hou module imported.
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import PyQt4
Traceback (most recent call last):
File “<console>”, line 1, in <module>
ImportError: No module named PyQt4
>>>

if in your system have python 2.7 with PyQt4 installed.
than you can add PyQt4 path (/usr/local/lib/python2.7/site_packages) in houdini sys.path
you may get following Error
ImportError: /usr/local/lib/python2.7/site-packages/PyQt4/_qt.so: undefined symbol: PyUnicodeUCS2_AsLatin1String

To Fix This Issue you should recompile PyQt against Hython (Houdini Python)

The Process of Compile PyQt for Houdini 13 on Centos 6.5

## Create Folder Structure
mkdir /tmp/Houdini_PyQt
mkdir -p /tmp/Houdini_PyQt/{bin,include,include/python2.7,lib,lib/python2.7,plugins,share,share/sip}

## Install QT
cd /tmp
wget http://download.qt-project.org/official_releases/qt/4.8/4.8.6/qt-everywhere-opensource-src-4.8.6.tar.gz
tar xvf qt-everywhere-opensource-src-4.8.6.tar.gz
cd qt-everywhere-opensource-src-4.8.6
./configure
make
make install
PATH=/usr/local/Trolltech/Qt-4.8.6/bin:$PATH
export PATH

## Install SIP
cd /tmp
wget http://sourceforge.net/projects/pyqt/files/sip/sip-4.16.2/sip-4.16.2.tar.gz
tar xvf sip-4.16.2.tar.gz
cd sip-4.16.2
hython configure.py –bindir=/tmp/Houdini_PyQt/bin –destdir=/tmp/Houdini_PyQt/lib/python2.7 –incdir=/tmp/Houdini_PyQt/include/python2.7 –sipdir=/tmp/Houdini_PyQt/share/sip
make
make install

## Install PyQt4
cd /tmp
wget http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.1/PyQt-x11-gpl-4.11.1.tar.gz
tar xvf PyQt-x11-gpl-4.11.1.tar.gz
cd PyQt-x11-gpl-4.11.1
## edit the configure.py and add the python command:
## sys.path.append(‘/tmp/Houdini_PyQt/lib/python2.7’) just before the line import sipconfig
hython configure.py –bindir=/tmp/Houdini_PyQt/bin –destdir=/tmp/Houdini_PyQt/lib/python2.7 –plugin-destdir=/tmp/Houdini_PyQt/plugins –sipdir=/tmp/Houdini_PyQt/share/sip –assume-shared
make
make install

 

Now copy /tmp/Houdini_PyQt folder to common location and add “Houdini_PyQt/lib/python2.7” in sys.path and add in PYTHONPATH

To Test PyQt4 in Houdini go to shelh and create new tool and in scripts window copy following code:

#================================================================================================================================================================================#

“””
This Python Script will display Python and PyQt Version Installed in Houdini.
“””
import sys
path = ‘/Houdini_PyQt/lib/python2.7’ # Add Houdini PyQt path here
if not path in sys.path:
sys.path.append(path)

import getpass
import PyQt4
import PyQt4.pyqtconfig
from PyQt4 import QtGui

PYQTVERSION = PyQt4.pyqtconfig.Configuration().pyqt_version_str
USER = getpass.getuser()
PYTHONVERSION = sys.version

app = QtGui.QApplication(sys.argv)
QtGui.QMessageBox.information(None, ‘PyQt Information’, ‘Hello %s\nyour python version is %s\n\nyour PyQt version is %s’% (USER,PYTHONVERSION,PYQTVERSION))

#================================================================================================================================================================================#

Now you are ready to drive with PyQt Gui Framework inside Houdini

houdini_PyQt4_001

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s