Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt4 and pyuic4

Tags:

python

pyqt

I'm trying to compile my first .ui file using PyQt4 on a mac with osx 10.6. I'm getting a syntax error and I'm not sure what it means.

>>> import sys
>>> sys.path.append('/Users/womble/Dropbox/scratch/')
>>> from PyQt4 import QtCore, QtGui
>>> pyuic4 Urb.ui > Urb.py

File "<stdin>", line 1
    pyuic4 Urb.ui > Urb.py
             ^
SyntaxError: invalid syntax

I tried adding

#!/usr/bin/python2.5

as my first line to the .ui file and I still get the same problem.

Thanks for any suggestions.

like image 650
djq Avatar asked Dec 23 '22 01:12

djq


2 Answers

You're mixing Python and shell commands.

This is Python code and can be executed from an interactive Python session:

import sys
sys.path.append('/Users/womble/Dropbox/scratch/')
from PyQt4 import QtCore, QtGui

This is supposed to be run from a command prompt or terminal window. It's giving syntax errors in your Python interpreter because it's not Python:

pyuic4 Urb.ui > Urb.py
like image 141
Josh Kelley Avatar answered Dec 26 '22 12:12

Josh Kelley


I normally use pyuic4 from the command line in the following way:

pyuic4 -xo Urb.py Urb.ui

The x flag makes sure the generated Python code includes a small amount of additional code that creates and displays the GUI when it is executes as a standalone application.

The o flag specifies the output file to write to (in the example above: Urb.py)

like image 35
ChristopheD Avatar answered Dec 26 '22 10:12

ChristopheD