ImportError PyQt4

Post here if you need help with creating a Graphical User Interface in Python.

ImportError PyQt4

Postby kentman234 » Sat Sep 17, 2016 10:26 pm

Hello,

when I run my python 3.5.2 shell, I have this error:
Code: Select all
from PyQt4.QtCore import *
ImportError: No module named 'PyQt4'

Is there anyone who can help?

Thank you.
Last edited by Yoriz on Sat Sep 17, 2016 11:05 pm, edited 1 time in total.
Reason: First post lock. Added code tags.
kentman234
 
Posts: 3
Joined: Mon Aug 29, 2016 10:13 pm

Re: ImportError PyQt4

Postby Larz60+ » Sun Sep 18, 2016 2:12 am

Hello,

You don't have the PyQt4 module installed.

You need to run the following command from a terminal window while connected to the internet:
Code: Select all
pip install PtQt4


Larz60+
Larz60+
 
Posts: 1307
Joined: Thu Apr 03, 2014 4:06 pm

Re: ImportError PyQt4

Postby kentman234 » Sun Sep 18, 2016 8:42 am

Larz60+ wrote:Hello,

You don't have the PyQt4 module installed.

You need to run the following command from a terminal window while connected to the internet:
Code: Select all
pip install PtQt4


Larz60+


Hello,

I have PyQt4 installed. I installed it from some installer. Anyway I tried to run the command from the terminal window and I got this error:

Could not find a version that satisfies the requirement PyQt4 (from versions: )
No matching distribution found for PyQt4
kentman234
 
Posts: 3
Joined: Mon Aug 29, 2016 10:13 pm

Re: ImportError PyQt4

Postby Larz60+ » Mon Sep 19, 2016 8:18 pm

Hello,

check your path, and make sure it's running python 3.5 and not some other version.
That's what the error looks like. (Not saying that's the case, just something to check)

Also, not sure if PyQt4 runs on python 3.5, don't see it mentioned in the installation doc

run this code to see if package is in 3.5
Code: Select all
import tkinter.tix as tk
import tkinter.filedialog as tf
import pip

class GetPackages:
    def __init__(self, parent):
        self.w = parent
        self.bgc1='#ffffe5'
        self.bgc2='Lavender'
        self.bgc3='LightCyan'
        self.pkglist = None
        self.w.geometry('400x400+10+10')
        self.w.title("Larz60+ Python Package List")
        self.ProcessData()

    def GetPackagesfromPIP(self):
        self.pkglist = pip.get_installed_distributions()
        # self.pkgs = sorted(["{} -- {}".format(pkg.key, pkg.version) for pkg in pkglist])

    def ProcessData(self):
        w = self.w

        # Get Package list
        self.GetPackagesfromPIP()

        t1 = tk.Text(w, wrap=tk.WORD, undo=0, bg=self.bgc1)
        t1.pack(expand=1, fill=tk.BOTH)
        t1scroll=tk.Scrollbar(t1)
        t1.configure(yscrollcommand=t1scroll.set)
        t1scroll.config(command=t1.yview)
        t1scroll.pack(side=tk.RIGHT,fill=tk.Y)

        t1.insert(tk.END, "{Package Name} -- {Version Info}\n\n")
        for item in self.pkglist:
            # print("row: {} key: {} -- Version: {}".format(trow, item.key, item.version))
            t1.insert(tk.END, "   {} -- {}\n".format(item.key, item.version))

    def SaveAResults(self):
        filename = tf.askopenfilename()
        with open(filename, 'w') as f:
            for item in self.pkglist:
                f.write("{}")

if __name__ == '__main__':
    root = tk.Tk()
    GetPackages(root)
    root.mainloop()


Larz60+
Larz60+
 
Posts: 1307
Joined: Thu Apr 03, 2014 4:06 pm

Re: ImportError PyQt4

Postby kentman234 » Tue Sep 20, 2016 6:46 pm

Larz60+ wrote:
run this code to see if package is in 3.5



when I ran your code, I had this:


{Package Name} -- {Version Info}

pip -- 8.1.1
setuptools -- 20.10.1
kentman234
 
Posts: 3
Joined: Mon Aug 29, 2016 10:13 pm

Re: ImportError PyQt4

Postby Larz60+ » Fri Sep 23, 2016 10:37 am

Hello,

Then, It was not being installed where you think it should have been.
the python version in your path is where it has been installed.

(type path from command line)
also, typing python by itself will give version of python target

pip can be run from the Scripts directory (C:\Python35\Scripts\pip for example) to assure the proper version, but changing the path is what's needed.

You can change your path manually, or reinstall, making sure you select path update.

Larz60+
Larz60+
 
Posts: 1307
Joined: Thu Apr 03, 2014 4:06 pm


Return to GUI

Who is online

Users browsing this forum: Bing [Bot] and 1 guest