2

I use this script to start qt designer with my custom widgets (in Python 3) visible:

#!/usr/bin/env python3

import os, sys, subprocess

curDir = os.path.dirname(os.path.abspath(__file__))
params = list(sys.argv) # copy list
params[0] = 'designer' # "designer-qt4" on Linux

widgetsDir = os.path.join(curDir, 'wic', 'widgets')

# add search path for custom widgets and plugins for designer
os.putenv('PYQTDESIGNERPATH', widgetsDir)

subprocess.Popen(params)

But it looks like designer is using python 2.7 to use the widget plugins:

vic@ubuntu:~/wic$ python3 qt_designer.pyw 
vic@ubuntu:~/wic$   File "/home/vic/wic/wic/widgets/w_date_edit_plugin.py", line 63
    app.exec()
           ^
SyntaxError: invalid syntax

How to instruct designer to use Python 3, not Python 2?

I use Kubuntu 11.10, KDE 4.7.2, python3.2 and python2.7, PyQt v4.8.5 compiled for Python 3

Community
  • 1
  • 1
warvariuc
  • 57,116
  • 41
  • 173
  • 227

1 Answers1

2

It looks like PyQt does not allow for side-by-side installation of the designer plugin that handles custom widgets (libpythonplugin.so). So there will normally be a single plugin linked against either python2, or python3, but not both.

It would appear that Kubuntu currently installs the python2 version of the plugin (on my linux system, it's the other way around). If you want a python3 version of the plugin, just compile a replacement from source.

EDIT

To compile a replacement, first ensure you have the sip packages installed. I am no expert on ubuntu, but I think you will need the python-sip-dev and python3-sip-dev packages (plus any dependencies, of course).

Next, download the PyQt4 sources that match the version installed on your system. I was able to find some ubuntu pyqt source packages here.

Now unpack the tarball, cd into the resulting source directory (looks like it should be PyQt-x11-gpl-4.8.5 for Kubuntu 11.10), and then configure the build using python3:

$ cd ~/tmp
$ tar -xf python-qt4_4.8.5.orig.tar.gz
$ cd PyQt-x11-gpl-4.8.5
$ /usr/bin/python3.2 configure.py -c -j 4

If that completes without error, build it (but do not install it):

$ make

Using the above configuration options it takes about 5 mins to compile pyqt on my old i686-AMD64-X2-6000 system. Once complete, the libpythonplugin.so plugin should be in the PyQt-x11-gpl-4.8.5/designer directory.

You can now backup and remove the existing plugin (on my system it's in the /usr/lib/qt/plugins/designer directory), and copy over your new plugin.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • On my Windows machine i had to put Python dir into the path, for the `libpython.dll` to be found. So i think the python version is not hardcoded into `libpythonplugin.so`. What do you think? Could it be solved using some path tweaking? – warvariuc Nov 03 '11 at 05:22
  • Looks like `libpython2.7.so` is hardcoded into `libpythonplugin.so`. How do i compile `libpythonplugin` for python 3? Where do i get the source? – warvariuc Nov 03 '11 at 09:01
  • @warvariuc. I have edited my answer to include instructions on how to compile the plugin. – ekhumoro Nov 03 '11 at 14:15
  • It worked! It was simpler - i did install `PyQt-x11-gpl-4.8.6`, and it put the python3 version into `/usr/lib/x86_64-linux-gnu/qt4/plugins/designer/libpythonplugin.so`. I think it gets overwritten by package manager when updating the packages for my system. Thank you very much! – warvariuc Nov 03 '11 at 17:29