Python Forum

Full Version: Help converting python qt4 script to qt5
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

Could someone help with converting this pyqt4 script to pyqt5 please?
When i run it i get this error:

Error:
Traceback (most recent call last): File "/usr/local/bin/wlcreator.py", line 31, in <module> from PyQt4.QtGui import * ImportError: No module named PyQt4.QtGui
I've uploaded the script as an attachment

Thanks very much
Replace "from PyQt4..." to from PyQt5..."?
Hi,

I tried changing what you said and now i'm getting this error:

Error:
File "./wlcreator.py", line 54 print "COMMAND:",command ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print("COMMAND:",command)?
I've tried changing this line with the one it thinks it should be and now i get this error

Error:
File "./wlcreator.py", line 66 if len(output) > 0: print "OUTPUT:\n",output ^ SyntaxError: invalid syntax
Looks like your scripts are written in Python 2 and you are now using Python 3. print is a function in Python 3. Here is a porting guide.

https://docs.python.org/3/howto/pyporting.html
change your imports

import sys
import glob
import os
import tempfile
import subprocess
import shlex
import shutil
from configparser import ConfigParser
import urllib

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
and put all print in brackets
Thanks for all the help so far!

I have done as requested an now get this error

Error:
Traceback (most recent call last): File "./wlcreator.py", line 719, in <module> main = MainWindow() File "./wlcreator.py", line 266, in __init__ self.executable = BrowseControl("Exe path", "Select exe file", "Path to an Windows executable file", "", File "./wlcreator.py", line 102, in __init__ self.connect(self.edit, SIGNAL("textChanged(QString)"), self.edited) AttributeError: 'BrowseControl' object has no attribute 'connect'
self.edit.textChanged.connect(self.edited)