One of my friend received some tools developed in PySide for Maya recently. He tried to copy the latest pre-built binaries of PySide into Maya’s site-packages but got an import error. Therefore, we have to build the PySide for Maya from the ground up and this post is about the entire building process we’ve been through. Hope this note might be helpful for people who want to use PySide in Maya. :)
BTW, the PySide for Maya 2012 built by vc9 can be downloaded here, enjoy it!
Prerequisites
Build autodesk modified Qt
- download QT4.7.1 modified for Maya 2012 Service Pack 2
- extract files into C:\Qt\qt-adsk-4.7.1
- cd C:\qt\qt-adsk-4.7.1
- configure -platform win32-msvc2008 -release -no-qt3support
- jom -j N (N=how many cores do you want to use for compiling)
- set environment variable QTDIR=C:\qt-adsk-4.7.1
- append %QTDIR%\bin to your PATH environment variable
OK, let’s go for the packages of PySide. Assume we have following directory layout:
- D:\pyside_for_maya
- src\
- deploy\
Build Shiboken
- cd D:\pyside_for_maya\src
- git clone git://gitorious.org/pyside/shiboken.git
- cd shiboken
- apply the patch [optional]
- mkdir build
- cd build
- create a text file named
init_cache.txt
for cmake pre-load cache:
SET(CMAKE_BUILD_TYPE “Release” CACHE STRING “”); SET(CMAKE_INSTALL_PREFIX “d:/pyside_for_maya/deploy/shiboken” CACHE PATH “”); SET(BUILD_TESTS OFF CACHE BOOL “”); SET(MAYA_ROOT “path-to-maya” CACHE PATH “”); SET(PYTHON_EXECUTABLE “${MAYA_ROOT}/bin/mayapy.exe” CACHE FILEPATH “”); SET(PYTHON_INCLUDE_DIR “${MAYA_ROOT}/include/python2.6” CACHE PATH “”); SET(PYTHON_LIBRARY “${MAYA_ROOT}/lib/python26.lib” CACHE FILEPATH “”);
- cmake -G “NMake Makefiles JOM” -C “init_cache.txt” ..
- jom -j N ps. if you have the following error: [ 98%] Running generator for ‘shiboken’… jom: D:\pyside_for_maya\src\shiboken\build\shibokenmodule\CMakeFiles\shibokenmod ule.dir\build.make [shibokenmodule\shiboken\shiboken_module_wrapper.cpp] Error 2 jom: D:\pyside_for_maya\src\shiboken\build\CMakeFiles\Makefile2 [shibokenmodule\CMakeFiles\shibokenmodule.dir\all] Error 2 jom: D:\pyside_for_maya\src\shiboken\build\Makefile [all] Error 2 please copy QtCore4.dll from C:\Qt\qt-adsk-4.7.1\bin to D:\pyside_for_maya\src\shiboken\build\generator and execute jom again
- jom install
Build PySide
- copy all dlls from C:\Qt\qt-adsk-4.7.1\bin to D:\pyside_for_maya\deploy\shiboken\bin [optional]
- cd d:\pyside_for_maya\src
- git clone git://gitorious.org/pyside/pyside.git
- cd pyside
- mkdir build
- create
init_cache.txt
:
SET(CMAKE_BUILD_TYPE Release CACHE STRING “”) SET(CMAKE_INSTALL_PREFIX D:/pyside_for_maya/deploy/pyside CACHE PATH “”) SET(BUILD_TESTS OFF CACHE BOOL “”) SET(Shiboken_DIR D:/pyside_for_maya/deploy/shiboken/lib/cmake/Shiboken-1.1.2 CACHE PATH “”)7. make -G “NMake Makefiles JOM” -C “init_cache.txt” .. 8. jom -j N 9. jom install
Troubleshooting for compile error in step 8:
[ 47%] Building CXX object PySide/QtGui/CMakeFiles/QtGui.dir/PySide/QtGui/qmessagebox_wrapper.cpp.obj D:\pyside_for_maya\src\pyside\build\PySide\QtGui\PySide\QtGui\qmenu_wrapper.cpp(3720) : error C2589: ‘constant’ : illegal token on right side of ‘::’
D:\pyside_for_maya\src\pyside\build\PySide\QtGui\PySide\QtGui\qmenu_wrapper.cpp(3720) : error C2059: syntax error : ‘::’
jom: D:\pyside_for_maya\src\pyside\build\PySide\QtGui\CMakeFiles\QtGui.dir\build.make [PySide\QtGui\CMakeFiles\QtGui.dir\PySide\QtGui\qmenu_wrapper.cpp.obj] Error 2 qmessagebox_wrapper.cpp
jom: D:\pyside_for_maya\src\pyside\build\CMakeFiles\Makefile2 [PySide\QtGui\CMakeFiles\QtGui.dir\all] Error 2
jom: D:\pyside_for_maya\src\pyside\build\Makefile [all] Error 2
just fix the line 3720
in
D:\pyside_for_maya\src\pyside\build\PySide\QtGui\PySide\QtGui\qmenu_wrapper.cpp to ::QPoint* cppArg0 = QPoint::NULL;
Deploy PySide packages
Yeah, we are almost done! The last thing to do is to copy files from our deploy folder to path-to-maya\Python\lib\site-packages:
- shiboken\lib\site-packages\shiboken.pyd
- pyside\lib\site-packages\PySide
Besides, we also need to copy two dlls to path-to-maya\Python\lib\site\packages\PySide
- pyside\bin\pyside-python2.6.dll
- shiboken\bin\shiboken-python2.6.dll
Simple “Hello World!”
- extract hello_pyside_for_maya.rar to D:\
- execute the following commands in Maya’s script editor
import sys sys.path.append(r'D:\hello_pyside_for_maya') import mainwin as mw frame = mw.MainWindow() frame.show()
- If it executes successfully, you would see this simple window:
Congrats and enjoy the PySide in Maya. ;)
comments powered by Disqus