Maya and PyQt on Windows
I’ve created the following as a from-scratch guide for compiling and installing PyQt for Maya in a Windows environment. I did not use any non-essential shortcuts to assist in the process given the possibility that they will not be supported in the future or may lag behind new releases of Maya. By following this guide you should be able to install PyQt for any Maya release. I assume throughout this guide that you are familiar with Python and Python in Maya.
Preliminaries
Before you can begin you need to install the following:
- Microsoft Visual C++ 2008: I use the free express edition because I do not use Visual Studio very often. Regardless of your Visual Studio installation, make sure you have the most recent version (service pack updates and all). Note: You cannot use a newer version of the compiler, e.g. Microsoft Visual C++ 2010, because Maya and its components are compiled using the 2008 product and for compatibility you need to use the same version. This will eventually change with new releases of Maya, but as of Maya 2012 you must compile using Visual Studio 2008.
- Perl: A Perl installation is necessary in the Qt compilation process. I prefer Strawberry Perl.
- .NET 3.X SDK (x64 compilation only): You’ll need the latest version of the .NET SDK in the 3.X branch installed, which is associated with the C++ 2008 compiler. Yes, .NET 4.X is available, but that is for the 2010 C++ compiler, which you cannot currently use (see above). This is a large install, multiple GBs to download, so be prepared to wait hours for it to complete.
Step 1: Determine Correct Qt Version
To begin you will need to determine the version of Qt that matches the one installed with your Maya installation. In the bin folder of your Maya installation find and run designer.exe. This will load the Qt Designer application compiled for Maya’s Qt installation. In the Help menu open the About dialog, which shows version information including the version of Qt compiled for your particular Maya release.
Step 2: Download the Qt Source
Once you have the correct Qt version information you can download the source code for that version to compile. Qt is managed by a public gitorious repository located at:
You want to browse the tree:
and find the tag that matches the Qt version you found in step 1. Navigate to the gitorious page for that tag in your browser and find the “Download 4.X.X as tar.gz” to acquire the source files.
Step 3: Extract Qt Source
After downloading the source, extract it to:
- C:\Qt\4.X.X\qt\
replacing 4.X.X with your downloaded version. When correctly installed, the qt folder should act as the container for all of your qt files. Confirm this by ensuring that you have a C:\Qt\4.X.X\qt\bin\ folder and a C:\Qt\4.X.X\qt\configure.exe file. If your unzipping results in a different path adjust accordingly or use a different path at your own risk. ;)
A side note: I include the extra qt in the path, instead of using the version name as the root folder as I do in compiling the other software in this guide, to get around an issue in the PyQt compile process. The issue is that during PyQt configuration some of the paths are set incorrectly. Therefore, to ensure my explicitly assigned paths are the ones being used during PyQt compilation, I use this additional directory path so that I can debug and verify along the way that I’ve set everything correctly. If you’re comfortable with this compilation process it’s not strictly necessary, it’s just an easy way to give yourself more debugging input if your PyQt compilation process fails for any number of reasons.
Step 4: Configure Qt For Compilation
WARNING: Before proceeding with any compilation in this guide you should disable the auto-protect features of your anti-virus software. A number of the actions carried out during compilation appear suspect to anti-virus protection. If you do not disable this protection your anti-virus software may corrupt the compilation process as it tries to protect your system from what it perceives as an attack.
Next you will need to configure the Qt source for compilation. This is done using the Visual Studio Tools C++ command prompt. When Visual Studio C++ is installed the start menu folder contains a Visual Studio Tools folder where a shortcut to the Visual Studio 2008 Command Prompt is located.
32-bit compilation:
If you are compiling for 32 bit Maya run the Visual Studio 2008 Command Prompt as Administrator by right clicking on its start menu shortcut and selecting Run As Administrator from the context menu.
64-bit compilation:
If you are compiling for 64 bit Maya you need to use the 64-bit enabled Visual Studio 2008 Command Prompt, which is not available in the start menu by default. Instead navigate to the folder where Visual C++ 2008 is installed on your system. The default location is C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC. Inside the VC folder should be a bin folder which contains a number shortcuts to the various Visual Studio 2008 Command Prompts of different types. You want to run the Visual Studio 2008 x64 Command Prompt as administrator by right clicking on it and selecting Run As Administrator from the context menu.
Once open you will need to execute the following commands in the prompt to configure the Qt compilation:
cd C:\Qt\4.X.X\qt set QTDIR=C:\Qt\4.X.X\qt set PATH=%PATH%;C:\Qt\4.X.X\qt\bin configure -opensource -platform win32-msvc2008
Accept the license prompt that appears after executing line 4 by type ‘y’ at the prompt and hitting enter.
Line 2 specifies the root Qt source path as an environmental variable needed for compilation. Similarly, line 3 adds the Qt bin directory to the global path as needed by compilation. Finally, line 4 executes the configure process for the open source Qt on the Windows platform as specified by the command flags. Note that the platform flag remains win32-msvc2008 even if you are compiling a 64-bit version. The configure process will take a few minutes to complete. If it is successful you will see a message like:
Qt is now configured for building. Just run nmake.
If, however, this process fails you have my sympathy. Unfortunately, like all complex low-level compilation processes, the range of possible issues are too expansive to deal with here. I’ll briefly mention the most common and obvious ones, which are:
- Visual C++ isn’t fully installed/configured, in which case you will see errors like cannot locate windows.h.
- Perl isn’t fully installed/configured, in which case you will see errors like cannot locate QtCore/qconfig.h.
- You didn’t have permissions to install files to the installation folder. In that case the configuration process will fail almost immediately as it cannot write the intermediate files.
If your configure process fails, I would recommend:
- Check that your Perl and Visual Studio C++ installations were successful.
- Restart your computer to make sure everything you installed has been properly registered by Windows.
- Try executing the configure process again making sure you run the command prompt as administrator.
Step 5: Compile Qt
Now that Qt is configured (a quick congrats for getting through the tedium of reaching this point is in order) you are ready to build it. As the the final output of the configure process suggests, all you need to do is run:
nmake
This compilation process is going to take a long time, several hours at least. Keep your fingers crossed that it works the first time through! Once the compilation process is complete you’ll then need to install using the command:
nmake install
Step 6: Download SIP Source
Next we’re going to need SIP. SIP is a tool for binding Python and C++, which is exactly what we need for PyQt since it is dervied from the C++ Qt software. The SIP source is maintained by Riverbank Computing and is available at:
The latest stable version should be sufficient. I wouldn’t recommend building from the unstable repository trunk unless you want to use SIP for other bindings in your Maya environment.
Step 7: Extract SIP
Like we did with Qt, we need to extract SIP to a compilation location. In my case I created a C:\SIP folder to contain this and any future SIP installations and then extracted SIP within that directory and named the folder according to the version of the SIP source that I’d downloaded. The result is a root path to my SIP source of:
- C:\SIP\X.X.X\
where X.X.X is replaced by the version number, e.g. 4.1.2. If correctly unzipped you should find the C:\SIP\X.X.X\configure.py file in your SIP source folder.
Step 8: Compile The SIP Module
Unlike Qt, SIP is a Python module and is compiled using standard techniques for Python modules. The key to the compilation process is that you want to use Maya’s Python installation, not another Python installation you may have installed on your system. If you do have another installation of Python, especially if it is not the same version as the one shipped with Maya, you’ll need to remove it any references to it from your PATH and PYTHONPATH variables to prevent the compiler from utilizing it during the compilation process. Begin compilation by opening a new Visual Studio 2008 Command Prompt, you can certainly close the previous one for compiling Qt now, if you haven’t done so already, as it’s served its purpose.
Cleansing Environmental Variables
Note: Modifications to environmental variables from within the Visual Studio 2008 Command Prompt are limited to that prompt. They do not affect these environmental variables on the system at large, and the variables are reset to the default system values each time a new Visual Studio 2008 Command Prompt is opened. Consequently, you need not worry about the effects of changing the variables, and if you make a mistake while editing them you can simply open a new command prompt and they will be reverted to the original values.
If you do have an incompatible installation of Python installed then you are going to need to remove any paths associated with the offending installation prior to executing the compilation. The PYTHONPATH is the easiest to cleanse because it is not needed for the compile process. In this case simply execute the command
set PYTHONPATH=which removes the variable entirely. The PATH variable is a little bit trickier because you need many of the path entries. The easiest way I’ve found to achieve the desired result, which is removing the Python paths while leaving the others intact is to perform a substitution on the PATH variable that replaces the python paths with something innocuous. Consider a case where Python 2.7 is installed in a C:\python27 folder. Then the following command:
set PATH=%PATH:python27=dumb%
searches for any matches of ‘python27′ in the PATH variable and replaces them with ‘dumb’. The result is that the Python installation path of C:\python27 will become C:\dumb, which doesn’t exist on my system. If C:\dumb does exist on your system for whatever your reason you can certainly set it to something else by replacing the ‘dumb’ string in the command above with some other folder name that doesn’t exist on your system. Since the altered path doesn’t exist the compiler will ignore it during compilation and there are no longer any references to the incompatible Python installation either. You should now be ready to compile SIP.
Since your Python installation path could be anything, I reference the default path naming convention here, it may be useful to inspect your current PATH variable before proceeding to determine the best replacement. To do that execute the command
echo PATHto see the complete listing of the stored paths. If for some reason a general replacement as outlined above isn’t possible, you can always run the path replacement command multiple times to remove each path. For example, if you wanted to remove a particular entry, say C:\python27, from your PATH variable instead of the more general find and replace you could execute the command:
set PATH=%!!%
which would eliminate only that specific entry from the PATH variable.
To compile the SIP module begin by entering the following commands:
cd C:\SIP\X.X.X set LIB=%LIB%;"{YOUR_MAYA_PATH}\lib" set INCLUDE=%INCLUDE%;"{YOUR_MAYA_PATH}\include\python2.6" "{YOUR_MAYA_PATH}\bin\mayapy.exe" configure.py
In lines 2-4 you need to replace {YOUR_MAYA_PATH} with the full path to your Maya installation, e.g. C:\Program Files\Autodesk\Maya2012. Line 2 gives the compiler access to Maya’s Python library, line 3 gives the compiler access to the Python source files needed during compilation, and line 4 executes the configuration process. Once configuration is complete you can build the SIP module with nmake:
nmake
If your nmake command fails and you see a leading error with return code 0xc0000135 it means that you haven’t installed the x64 bit compilers necessary for the module. If you thought you were building for the 32 bit version of Maya, check to make sure the paths you entered correctly point to a 32 bit Maya installation. If you were intending to compile for 64 bit Maya then your installation of the .NET SDK is flawed in some way.
After a successful package build you want to deploy SIP to Maya for use in the Maya Python environment by running the command:
nmake install
If the nmake install command was successful the final lines echoed by the command should end in ’1 file(s) copied.’ This indicates that the compiled module elements were correctly deployed to your Maya installation.
Step 9: Test SIP
Before continuing it would be wise to check that SIP was correctly installed in Maya. To do that run Maya and in the Python script editor run the following commands:
import sip print sip.SIP_VERSION_STR
If they execute without error SIP is properly installed and ready for use and you should see the print command echo the version number that matches the version you’ve just compiled.
Step 10: Download PyQT Source
Finally we’re going to need the PyQt source, which, like SIP, is maintained by Riverbank Computing and is available at:
The latest stable version should be sufficient. I wouldn’t recommend building from the unstable repository trunk unless you want to experiment with some bleeding edge functionality.
Step 11: Extract PyQt
In a similar fashion to the two previous compilations, we’re going to want to extract PyQt to a versioned folder, C:\PyQt\4.X.X. Using this directory as the root for the PyQt source you should find the configure script at C:\PyQt\4.X.X\configure.py.
Step 12: Compile the PyQt Module
The final step is then to compile and deploy the PyQt module for your Maya installation. You will need to open yet another new Visual Studio 2008 Command Prompt.
Once again you may need to cleanse your environmental variables. In this case if you have another installation of Qt installed on your system other than the one you’ve just compiled as the version compatible with Maya, you’ll need to unlink and references to these incompatible Qt installations or the PyQt compile process may try to erroneously use them instead of the Qt version you’ve just compiled. See the above section on cleansing environmental variables for explanation of how to proceed.
Once your PATH variable is clean of any incompatible Qt installation path references you can proceed with the PyQt configuration process by executing the following commands:
cd C:\PyQt\4.X.X set QTDIR=C:\Qt\4.X.X\qt set PATH=%PATH:PyQt=DUMB% set PATH=C:\Qt\4.X.X\qt\bin;%PATH% set QMAKESPEC=C:\Qt\4.X.X\qt\mkspecs\win32-msvc2008 set INCLUDE=%INCLUDE%;"{YOUR_MAYA_INSTALLATION}\include\python2.6";"{YOUR_MAYA_INSTALLATION}\Python\include" "{YOUR_MAYA_INSTALLATION}\bin\mayapy.exe" configure.py -w LIBDIR_QT=C:\Qt\4.X.X\qt\lib INCDIR_QT=C:\Qt\4.X.X\qt\include
Then build the module using nmake as we’ve done before:
nmake
Note: During one of my installation attempts, I ran into problems during the compilation process. The configuration process had, for some unknown reason, assigned incorrect paths to some of the Qt files in the makefiles responsible for compiling the various components of PyQt. In my case the problem was the moc.exe entry, which appears in the various PyQt makefiles as:
MOC = {QT_INSTALL_FOLDER}\bin\moc.exewhere the QT_INSTALL_FOLDER should have been C:\Qt\4.X.X\qt, it was instead just C:\Qt. I was not able to track down the reason for the error, and subsequent configuration attempts resulted in the same incorrect value. Therefore, to get around the problem, I used a grep program to search through all files in the C:\PyQt\4.X.X directory and replace any erroneous entries with the correct path value. After that compilation completed without issue.
And finally deploy the module as well:
nmake install
Step 13: Test PyQt
Now that you have everything installed, run Maya and try executing the following commands in the Maya Python script editor:
from PyQt4 import QtCore print QtCore.PYQT_VERSION_STR
If your installation was successful you should get the version number of PyQt you just installed echoed back from the print statement. If so, congratulations, you’re ready to go.
I hope you’ve found this guide useful. I will try to maintain it to remain current as new software becomes available. If you see anything incorrect, missing, or unclear please let me know and I’ll do my best to correct it.

