PyQt4 and pyuic4

I am trying to compile my first .ui file using PyQt4 on mac with osx 10.6. I am getting a syntax error and I'm not sure what that 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 

like my first line in the .ui file, and I still get the same problem.

Thanks for any suggestions.

+4
source share
3 answers

You mix Python commands and shells.

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 

It is assumed that it is launched from the command line or terminal window. This gives syntax errors in the Python interpreter because it is not Python:

 pyuic4 Urb.ui > Urb.py 
+9
source

I usually use pyuic4 from the command line as follows:

 pyuic4 -xo Urb.py Urb.ui 

The x flag ensures that the generated Python code contains a small amount of additional code that creates and displays a graphical interface when it runs as a stand-alone application.

The o flag indicates the output file for writing (in the example above: Urb.py)

+2
source

After almost 6 hours of finding the right solution, the steps on this page are by far the most accurate, which worked perfectly on my mac 10.6.8

http://www.pythonsummerschool.net/index.php?url=mac_pyqt

Now I can convert * .ui files to * .py files on the terminal:

Once you have installed pyQt using sip and all the relevant dependencies, as described in this link, you need to go to / Applications / Python 3.2 / Update Shell Profile.command and run it.

Check path variables: env | grep PATH

Once everything points to your last Python installation, you can double check by running / Applications / Python 3.2 / Update Shell Profile.command

Then it is as simple as pyuic4 / Volumes / BOOTCAMP / yourfile.ui> /Volumes/BOOTCAMP/yourfile.py

Good luck

0
source

Source: https://habr.com/ru/post/1314983/


All Articles