This is a continuation of the previous post and this time we will focus on building PySide.
PySide [http://www.pyside.org/ or http://qt-project.org/wiki/PySide/] is a python binding to the Qt library. Because Maya uses Qt internally, you can use the PySide modules in Maya python scripts to create custom UI. PySide does not have the same licensing as Maya, Qt, or Python. Please consult the PySide website for information about licensing for PySide.
Download Shiboken & PySide: http://qt-project.org/wiki/PySideDownloads
Download Cmake: http://www.cmake.org/cmake/resources/software.html
Maya 2013 uses Qt4.7.1 which is binary compatible with the latest version of PySide-1.1.2 (at time of writing, October 2012).
Building Qt
Like for PyQt, you need to build Qt from the Autodesk modified source, so before you start read the previous post on how to build Qt. There is nothing different here for building PySide.
Building Shiboken and PySide
Like SIP for PyQt, PySide needs a supplementary library to interface C++ code to Python, and this is Shiboken. The few first version of PySide was using Boost which is a great library for Python and many other things, but Boost has a large footprint compared to Shiboken, and PySide quickly moved to Shiboken instead of Boost.

Building Shiboken
If you go to the PySide page you'll get instructions on how to build Shiboken for all platforms. But I found these instructions are either wrong, too complicated, requires unneeded dependencies and all over the place. Because I hate to pollute my developer machine with all unnecessary tools, I reduced the build procedure to the minimum needed. That also make sense because I am not building PySide everyday.
However you will need to download Cmake to build PySide and Shiboken. The Cmake utility is available here. Download and unzip Cmake in a folder or install Cmake using the installer as you prefer. You may also want to install few additional libraries on Linux even they aren't strictly needed, but would avoid true-wrong error messages.
yum install libxml2-devel libxslt-devel
For the rest of the post, I assume you installed Cmake on the following folders:
- Windows x64 = c:\cmake-2.8.9-win32-x86
- OSX x86 64 bit = /Users/myHomeDir/cmake
- Linux = ~/cmake
To avoid script issues later on OSX, please go in the cmake folder and rename the "CMake 2.8.9.app" into "CMake-2.8.9.app". Apparently scripts do not like spaces even using the escape sequence.
Windows x64
The following instructions only apply to 64‐bit builds of Windows Shiboken. You will need to have Visual Studio 2010 SP1 with x64 tools installed. These instructions may also work with Visual Studio Express 2010 Edition. (qt-project.org instructions here)
- Extract the archive to a folder (e.g. C:\shiboken-1.1.2)
- Start up a Visual Studio 2010 x64 Win64 Command Prompt
- cd C:\shiboken-1.1.2
- Setup the environment
set CMAKE=c:\cmake-2.8.9-win32-x86\bin\cmake.exe
set QMAKE=c:\qt-adsk-4.7.1\qmake.exe
set MAYA_LOCATION=C:\Program Files\Autodesk\Maya2013
set PYTHON_EXEC="%MAYA_LOCATION%\bin\mayapy.exe"
set PYTHON_INC="%MAYA_LOCATION%\include\python2.6"
set PYTHON_LIB="%MAYA_LOCATION%\lib\python26.lib" - Create a directory _build
mkdir _build
cd \shiboken-1.1.2\_build - Generate makefiles using Cmake
%CMAKE% -G "NMake Makefiles" -DQT_QMAKE_EXECUTABLE=%QMAKE% -DBUILD_TESTS=False -DPYTHON_EXECUTABLE=%PYTHON_EXEC% -DPYTHON_INCLUDE_DIR=%PYTHON_INC% -DPYTHON_LIBRARY=%PYTHON_LIB% -DCMAKE_BUILD_TYPE=Release .. - nmake
- nmake install/fast
this will install files into 'C:\Program Files\shiboken' and not in Maya's Python folder
- copy "C:\Program Files\shiboken\lib\site-packages\shiboken.pyd" "C:\Program Files\Autodesk\Maya2013\Python\Lib\site-packages"
- copy "C:\Program Files\shiboken\bin\shiboken-python2.6.dll" "C:\Program Files\Autodesk\Maya2013\Python\Lib\site-packages"
You're done.
OSX x86 64 bit
The following instructions only apply to Mac 64‐bit builds of PyQt. Note that in case you build on Lion (10.7) that you need the MacOS Snow Leopard SDK (10.6) to build Qt and Maya plug-ins. (qt-project.org instructions here)
- untar shiboken-latest.tar.bz2
- cd shiboken-1.1.2
- Setup the environment
export CMAKE=/Users/myHomeDir/cmake/CMake-2.8.9.app/Contents/bin/cmake
export QMAKE=/Users/myHomeDir/qt-4.7.1/bin/qmake
export MAYA_LOCATION=/Applications/Autodesk/maya2013
export PYTHON_EXEC=$MAYA_LOCATION/Maya.app/Contents/bin/mayapy
export PYTHON_SITE=$MAYA_LOCATION/Maya.app/Contents/Frameworks/Python.framework
export PYTHON_INC=$PYTHON_SITE/Headers
export PYTHON_LIB=/usr/lib/libpython2.6.dylib - Create directories _output and _build
mkdir _output
mkdir _build
cd _build - Generate makefiles using Cmake
$CMAKE -DQT_QMAKE_EXECUTABLE=$QMAKE -DBUILD_TESTS=False -DPYTHON_EXECUTABLE=$PYTHON_EXEC -DPYTHON_INCLUDE_DIR=$PYTHON_INC -DPYTHON_LIBRARY=$PYTHON_LIB -DCMAKE_BUILD_TYPE=Release -DENABLE_ICECC=0 -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.6.sdk -DCMAKE_INSTALL_PREFIX=/Users/myHomeDir/shiboken-1.1.2/_output .. - make
- make install/fast
At this time Shiboken is installed in '/Users/myHomeDir/shiboken-1.1.2/_output' and not in Maya's Python folder. Because binaries will need special treatments to work in Maya, please refer to the special Mac OSX install procedure at the end of this post after having built PySide below.
Linux x86 64 bit
The following instructions only apply to Linux 64‐bit builds of PySide. The first thing described in the Maya 2013 documentation for building on Linux is that you need the GCC 4.1.2 compiler. See here - details to rebuild GCC for Maya 2013 are in my previous post. (qt-project.org instructions here)
- untar shiboken-latest.tar.bz2
- cd shiboken-1.1.2
- Setup the environment
export CMAKE=~/cmake/bin/cmake
export QTDIR=/usr/local/Trolltech/Qt-4.7.1
export QMAKE=$QTDIR/bin/qmake
export MAYA_LOCATION=/usr/autodesk/maya2013-x64
export PYTHON_EXEC=$MAYA_LOCATION/bin/mayapy
export PYTHON_INC=$MAYA_LOCATION/include/python2.6
export PYTHON_LIB=$MAYA_LOCATION/lib/libpython2.6.so
export CMAKE_C_COMPILER=/opt/gcc412/bin/gcc412
export CMAKE_CXX_COMPILER=/opt/gcc412/bin/g++412 - Create directories _output and _build
mkdir _output
mkdir _build
cd _build - Generate makefiles using Cmake
$CMAKE -DQT_QMAKE_EXECUTABLE=$QMAKE -DBUILD_TESTS=False -DPYTHON_EXECUTABLE=$PYTHON_EXEC -DPYTHON_INCLUDE_DIR=$PYTHON_INC -DPYTHON_LIBRARY=$PYTHON_LIB -DCMAKE_BUILD_TYPE=Release -DENABLE_ICECC=0 -DCMAKE_INSTALL_PREFIX=~/shiboken-1.1.2/_output -DCMAKE_C_COMPILER=$CMAKE_C_COMPILER -DCMAKE_CXX_COMPILER=$CMAKE_CXX_COMPILER .. - make
- make install/fast
At this time Shiboken is installed in '~/shiboken-1.1.2/_output' and not in Maya's Python folder. - cd $MAYA_LOCATION/lib/python2.6/site-packages
cp ~/shiboken-1.1.2/_output/lib/libshiboken-python2.6.so.1.1.2 .
ln -s libshiboken-python2.6.so.1.1.2 libshiboken-python2.6.so.1.1
ln -s libshiboken-python2.6.so.1.1 libshiboken-python2.6.so
cp ~/shiboken-1.1.2/_output/lib/python2.6/site-packages/shiboken.so . - Create a file named shiboken.conf in /etc/ld.so.conf.d and add the following line
/usr/autodesk/maya2013-x64/lib/python2.6/site-packages - sudo ldconfig
Building PySide
Like for Shiboken, instructions on the PySide page are over complicated to my taste. While it is fine to use with minor adjustments, find below some instructions which I used to build PySide without downloading tools I do not need in my everyday work.
Windows x64
The following instructions only apply to 64‐bit builds of Windows PySide. You will need to have Visual Studio 2010 SP1 with x64 tools installed. These instructions may also work with Visual Studio Express 2010 Edition. (qt-project.org instructions here)
One last minute update - the Maya 2013 Extension includes qmake.exe in its bin folder (I.e.: 'C:\Program Files\Autodesk\Maya2013.5\bin'), so delete or rename it while you build PySide or you'll get strange errors later.
- Extract the archive to a folder (e.g. C:\pyside-qt4.8+1.1.2)
- Start up a Visual Studio 2010 x64 Win64 Command Prompt
- cd C:\pyside-qt4.8+1.1.2
- Setup the environment
set CMAKE=c:\cmake-2.8.9-win32-x86\bin\cmake.exe
set QMAKE=c:\qt-adsk-4.7.1\qmake.exe
set SHIBOKEN="C:\Program Files\shiboken"
subst s: /d
subst s: %SHIBOKEN%
set SHIBOKEN_DIR=s:\lib\cmake\Shiboken-1.1.2 - Create a directory _build
mkdir _build
cd \pyside-qt4.8+1.1.2\_build - Generate makefiles using Cmake
%CMAKE% -G "NMake Makefiles" -DQT_QMAKE_EXECUTABLE=%QMAKE% -DBUILD_TESTS=False -DCMAKE_BUILD_TYPE=Release -DShiboken_DIR=%SHIBOKEN_DIR% .. - nmake
- nmake install
this will install files into 'C:\Program Files\pysidebindings' and not in Maya's Python folder
- Create a folder PySide in Maya's Python folder
mkdir "C:\Program Files\Autodesk\Maya2013\Python\Lib\site-packages\PySide" - copy "C:\Program Files\shiboken\bin\shiboken-python2.6.dll" "C:\Program Files\Autodesk\Maya2013\Python\Lib\site-packages\PySide"
- copy "C:\Program Files\pysidebindings\bin\pyside-python2.6.dll" "C:\Program Files\Autodesk\Maya2013\Python\Lib\site-packages\PySide"
- copy "C:\Program Files\pysidebindings\lib\site-packages\PySide\*.*" "C:\Program Files\Autodesk\Maya2013\Python\Lib\site-packages\PySide"
You're done.
OSX x86 64 bit
The following instructions only apply to Mac 64‐bit builds of PyQt. Note that in case you build on Lion (10.7) that you need the MacOS Snow Leopard SDK (10.6) to build Qt and Maya plug-ins. (qt-project.org instructions here)
- untar pyside-latest.tar.bz2
- cd pyside-qt4.8+1.1.2
- Setup the environment
export CMAKE=/Users/myHomeDir/cmake/CMake-2.8.9.app/Contents/bin/cmake
export QTDIR=/Users/myHomeDir/qt-4.7.1
export QMAKE=$QTDIR/bin/qmake
export SHIBOKEN_DIR=/Users/myHomeDir/shiboken-1.1.2/_output - Create directories _build and _output
mkdir _output
mkdir _build
cd _build - Generate makefiles using Cmake
$CMAKE -DQT_QMAKE_EXECUTABLE=$QMAKE -DBUILD_TESTS=False -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.6.sdk -DShiboken_DIR=$SHIBOKEN_DIR -DCMAKE_INSTALL_PREFIX=/Users/myHomeDir/pyside-qt4.8+1.1.2/_output -DALTERNATE_QT_INCLUDE_DIR=$QTDIR/include .. - make
- make install
At this time PySide is installed in '/Users/myHomeDir/pyside-qt4.8+1.1.2/_output' and not in Maya's Python folder. Because binaries will need special treatments to work in Maya, please refer to the special Mac OSX install procedure at the end of this post below.
Linux x86 64 bit
The following instructions only apply to Linux 64‐bit builds of PySide. The first thing described in the Maya 2013 documentation for building on Linux is that you need the GCC 4.1.2 compiler. See here - details to rebuild GCC for Maya 2013 are in my previous post. (qt-project.org instructions here)
- untar pyside-latest.tar.bz2
- cd pyside-qt4.8+1.1.2
- Setup the environment
export CMAKE=~/cmake/bin/cmake
export QMAKE=/usr/local/Trolltech/Qt-4.7.1/bin/qmake
export MAYA_LOCATION=/usr/autodesk/maya2013-x64
export SHIBOKEN_DIR=~/shiboken-1.1.2/_output/lib/cmake/Shiboken-1.1.2
export CMAKE_C_COMPILER=/opt/gcc412/bin/gcc412
export CMAKE_CXX_COMPILER=/opt/gcc412/bin/g++412
export LD_LIBRARY_PATH=$MAYA_LOCATION/lib - Create directories _build and _output
mkdir _output
mkdir _build
cd _build - Generate makefiles using Cmake
$CMAKE -DQT_QMAKE_EXECUTABLE=$QMAKE -DBUILD_TESTS=False -DCMAKE_BUILD_TYPE=Release -DShiboken_DIR=$SHIBOKEN_DIR -DCMAKE_C_COMPILER=$CMAKE_C_COMPILER -DCMAKE_CXX_COMPILER=$CMAKE_CXX_COMPILER -DCMAKE_INSTALL_PREFIX=~/pyside-qt4.8+1.1.2/_output .. - make
- make install
At this time PySide is installed in '~/pyside-qt4.8+1.1.2/_output' and not in Maya's Python folder. - cd $MAYA_LOCATION/lib/python2.6/site-packages
mkdir PySide
cd PySide
cp ~/pyside-qt4.8+1.1.2/_output/lib/libpyside-python2.6.so.1.1.2 .
ln -s libpyside-python2.6.so.1.1.2 libpyside-python2.6.so.1.1
ln -s libpyside-python2.6.so.1.1 libpyside-python2.6.so
cp ~/pyside-qt4.8+1.1.2/_output/lib/python2.6/site-packages/PySide/* . - Create a file named pyside.conf in /etc/ld.so.conf.d and add the following line
/usr/autodesk/maya2013-x64/lib/python2.6/site-packages/PySide - sudo ldconfig
Special instructions to finalize install on Mac OSX
Ok, we now assume both Shiboken and PySide successfully built into '/Users/myHomeDir/shiboken-1.1.2/_output' and '/Users/myHomeDir/pyside-qt4.8+1.1.2/_output'.
Rather than a long description, I copied below my install script, you only need to adjust one (or two) path accordingly to your machine set-up.
- Copy&Paste the script below into a script file (for example my-pyside-install-script)
- Edit the paths marked in code below to fit your machine set-up
- sudo ./my-pyside-install-script
Code to copy and paste into a bash script
#!/usr/bin/env bash export MYHOME=/Users/myHomeDir export DOCS=$MYHOME export MAYA_LOCATION=/Applications/Autodesk/maya2013 export PYTHON_SITE=$MAYA_LOCATION/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages # Config shiboken / PySide export SHIBOKEN=$DOCS/shiboken-1.1.2/_output/lib export PYSIDE=$DOCS/pyside-qt4.8+1.1.2/_output/lib cd $PYTHON_SITE cp $SHIBOKEN/libshiboken-python2.6.1.1.2.dylib . ln -s libshiboken-python2.6.1.1.2.dylib libshiboken-python2.6.1.1.dylib ln -s libshiboken-python2.6.1.1.dylib libshiboken-python2.6.dylib cp $SHIBOKEN/python2.6/site-packages/shiboken.so . mkdir PySide cd PySide cp $SHIBOKEN/libshiboken-python2.6.1.1.2.dylib . ln -s libshiboken-python2.6.1.1.2.dylib libshiboken-python2.6.1.1.dylib ln -s libshiboken-python2.6.1.1.dylib libshiboken-python2.6.dylib cp $PYSIDE/libpyside-python2.6.1.1.2.dylib . ln -s libpyside-python2.6.1.1.2.dylib libpyside-python2.6.1.1.dylib ln -s libpyside-python2.6.1.1.dylib libpyside-python2.6.dylib cp $PYSIDE/python2.6/site-packages/PySide/* . # The following 4 lines are one single line each to execute properly for mod in QtCore QtDeclarative QtDesigner QtDesignerComponents QtGui QtHelp QtMultimedia QtNetwork QtOpenGL QtScript QtScriptTools QtSql QtSvg QtWebKit QtXml QtXmlPatterns phonon; do find /Applications/Autodesk/maya2013/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/PySide -name "*.so" -exec install_name_tool -change ${mod}.framework/Versions/4/${mod} @executable_path/${mod} {} \;;done; for mod in QtCore QtDeclarative QtDesigner QtDesignerComponents QtGui QtHelp QtMultimedia QtNetwork QtOpenGL QtScript QtScriptTools QtSql QtSvg QtWebKit QtXml QtXmlPatterns phonon; do find /Applications/Autodesk/maya2013/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/PySide -name "*.dylib" -exec install_name_tool -change ${mod}.framework/Versions/4/${mod} @executable_path/${mod} {} \;;done; for mod in libpyside-python2.6.1.1.dylib libshiboken-python2.6.1.1.dylib ; do find /Applications/Autodesk/maya2013/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/PySide -name "*.so" -exec install_name_tool -change ${mod} @executable_path/../Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/PySide/${mod} {} \;;done; for mod in libpyside-python2.6.1.1.dylib libshiboken-python2.6.1.1.dylib ; do find /Applications/Autodesk/maya2013/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/PySide -name "*.dylib" -exec install_name_tool -change ${mod} @executable_path/../Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/PySide/${mod} {} \;;done;
Test PySide in Maya
Simply copy and paste this code into a Maya Python tab in the script editor and run it. If it works, you are all set :)
import sys from PySide import QtCore, QtGui class FormExample(QtGui.QWidget): def __init__(self): super(FormExample, self).__init__() self.initUI() def initUI(self): QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10)) self.setToolTip('This is my <b>QWidget</b> widget tooltip') btn = QtGui.QPushButton('My Button', self) btn.setToolTip('This is my <b>QPushButton</b>') btn.resize(btn.sizeHint()) btn.move(50, 50) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('My Form Example') self.show() ex = FormExample()
ok we're done now :)
Can You write something about MPxContext and MPxContextCommand for Python? There is really a lack of information about this subject on the internet.
Posted by: Kayla | October 09, 2012 at 09:31 AM
PySide and Qt are both LGPL licenses. Did you mean to say PySide and PyQt have different licenses?
Posted by: Tony | October 10, 2012 at 03:53 AM
Hi Kyala,
Sure, I'll keep that in my list of thing to do, and it grows everyday ;)
Posted by: Cyrille Fauvel | October 10, 2012 at 09:24 AM
Hi Tony
I am not a legal person, but our legal department told me last year, they are different and that as an Autodesk employee I need to be careful with that. Especially about termination...
Posted by: Cyrille Fauvel | October 10, 2012 at 09:33 AM
You say you absolutely have to use Qt4.7.1. However, I have compiled against 4.7.3 for both pyQt and PySide and there are no problems. However, 4.7.4 does not compile correctly.
Posted by: aj | November 05, 2012 at 12:08 PM