Hi guys,

I have recently decided to start doing some work using PyQt, I've been told its pretty good, however I hit a bit of a block when I installed Python 2.6 and PyQt4 only to find that every time I try to run any code that uses any PyQt module comes up with an error.

Here are the details of my problem, hopefully someone can help:

  • Installed PyQt4 from Here
  • Installed Python 2.6.5 from the python website
  • I am running windows 7 64 bit
  • I tried running script from a tutorial Here
  • Receive an error message (from IDLE) for ALL programs which have this line (from PyQt4 import QtGui) or any other like it (ie including QtGui)
  • Error message is:
    Traceback (most recent call last):
      File "E:\Documents\Work\PyQt stuff\Resize windows.py", line 6, in <module>
        from PyQt4 import QtGui
    ImportError: DLL load failed: %1 is not a valid Win32 application.

Only thoughts I've really had about this are:

  • Its possible because I am running windows, especially considering "!/usr/bin/python" is pointing to where python is on a linux machine, howevers commented so I don't really know how this works
  • The binary I used has an issue, most installations on windows that I have seen go through a series of relatively complicated steps to get to the same point I am at now, something in the binary might to quite fit the bill in terms of doing everything necessary for pyqt to run properly
  • Seeing as this is the first time I have used PyQt the programs I have tried to run may be looking for something created in the developer, of which I have none.
  • The actual program is saved on my E:/ whereas python and pyqt is installed on my C:/, although this doesn't seem particularly likely, as I'm sure it would work to load a script from a USB or other such device

Anyway, any help would be greatly appreciated as I am at a loss as to what to do, if anyone need any more information about my machine or what I have done in terms of installing pyqt I am happy to provide it.

Thanks

Lmnopt

Are you using 64-bit Python?
If so, this is likely to be the issue. Unfortunately, you will need to uninstall all the python modules you have and reinstall them on a 32-bit version of Python. Some modules such as Pygame and PyQt4 do not yet have support for 64-bit Python.

I am running 64-bit Windows 7 Home Premium with Python 2.6.4, and since I did this for pyGame, I have had no further issues.

I would agree with SgtMe.
Even though you are running Windows7-64bit, you are better of to install the 32bit versions of Python and PyQt at this time.

Thanks for the responses guys,

I'm currently downloading all the files again, although I'm fairly sure that I installed the 32bit version of python as that is the only file that i have on my computer in terms of installing python. However as I was downloading all of the files again I noticed something, in the URL to the pyqt4 that I downloaded it says 64 bit

http://code.google.com/p/pyqt4-win64-binaries/downloads/list

And in the error message it came up as not a valid win32 operation. So now I'm downloading the 64 bit version as well, so I'll just try installing combination's of 32 and 64 bit and hopefully one works.

I'll reply here with how it went once I'm finished.

Ok, after spending a while trying to reinstall python 2.6 and pyqt I've hit another problem.

I uninstalled both and reinstalled 2.6 64 bit and pyqt, still didn't work

uninstalled both, again

when I attempt to reinstall python 2.6.5 I get an error, about half way through the installation I get

The cabinet file 'python' required for this installation is corrupt and cannot be used. This could indicate a network error, an error reading from the CD-ROM, or a problem with this package.

I looked this error up and apparently it has something to do with msi files, the only issue being that I have downloaded it before and installed it so it must be something machine specific if it doesn't work this time.

Any help would be greatly appreciated.

Thanks

Might have been incomplete uninstall.

This is the way I installed PyQt on my Windows XP machine and it works fine.
For Python26 download (latest versions as of 4/3/2010):
python-2.6.5.msi
Windows installer from
http://www.python.org/download/releases/2.6.5/

PyQt-Py2.6-gpl-4.7.2-1.exe
Windows installer from
http://www.riverbankcomputing.co.uk/software/pyqt/download

This was my little test program:

# pqt_Slider_LCD.py
# create PyQt form with slider and LCD readout
# get changing slider values for potentially other uses

# for easier syntax import this way
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class MyForm(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.setWindowTitle('show slider value')
        self.resize(250,150)

        self.lcd = QLCDNumber(self)
        # default slider values are 0 to 99
        self.slider = QSlider(Qt.Horizontal, self)

        # use vertical layout
        vbox = QVBoxLayout()
        vbox.addWidget(self.lcd)
        vbox.addWidget(self.slider)
        self.setLayout(vbox)

        # connects the slider to the lcd number in change_value()
        # and also allows access to the slider value as it changes
        self.connect(self.slider, SIGNAL('valueChanged(int)'),
            self.change_value)

    def change_value(self, event):
        """show the changing slider value in the LCD display"""
        val = self.slider.value()
        print(val, type(val))  # test
        # display value in the LCD widget
        self.lcd.display(val)


app = QApplication([])
mf = MyForm()
mf.show()
app.exec_()

Thanks for the replies bumsfeld, I figured it might have been complete uninstall and I found that I had python 3.1, 2.3, 2.4 and 2.5 all installed somewhere, although I couldn't find the actual files.

I uninstalled all of those and have been looking for some sort of solution however I simply can't find a way to get past the aforementioned error.

If anyone can help out with just installing python 2.6 it would help immensely.

Thanks

I just did Bumsfeld's Python26 and PyQt 32bit installation on my Dell Window7-64bit machine and it worked perfectly well.

still struggling with the whole installing python in the first place

msi files are pretty tricky things, here are a few things you can try:

  • Download it using a different browser
  • Download it on a different os (assuming you are dual booting)
  • Download it on a different machine and just transfer it across.

I know that none of shat should work but trust me, just try it.

thank you hazar, that worked perfectly.

An explanation as to why would be nice..... I can't see why downloading from another computer should work, but regardless of that I finally have python installed on my computer!

Now to try installing pyqt again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.