25 Feb 2010

PyQt4 Generate Code Problem

There are some unknown problem for PyQt4 while generating code in Windows. The error message is:

"code generation failed" 
"Unable to launch $YourPythonPath/Lib/site-packages/PyQt4/.\uic."

I haven't found any way to fix it. But the code can be generated successfully by invoking the command like:
"pyuic4 -o codeFile.py -x yourUIfile.ui"

it's more convenient to run the following script in the same path as source code file:
import os
for root, dirs, files in os.walk('.'):
    for file in files:
        if file.endswith('.ui'):
            os.system('pyuic4 -o %s.py -x %s' \
                      % (file.rsplit('.', 1)[0], file))
        elif file.endswith('.qrc'):
         os.system('pyrcc4 -o %s_rc.py %s' \
                      % (file.rsplit('.', 1)[0], file))

No comments :

Post a Comment