Problem with Python 2.6 and PyQt4 on Windows

Showing 1-7 of 7 messages
Problem with Python 2.6 and PyQt4 on Windows Nathan Weston 10/8/10 8:17 AM
I'm trying to package a trivial PyQt app with Python 2.6 on Windows.
As recommended on the Wiki, I'm using the trunk (r897) for WinSxS
support.

My exe builds without errors, but when run it can't find PyQt:

Traceback (most recent call last):
  File "<string>", line 14, in <module>
  File "C:\home\nathan\src\pyinstaller-trunk-r897\iu.py", line 455, in
importHook
    raise ImportError, "No module named %s" % fqname
ImportError: No module named PyQt4.QtCore

The warnings file generated by Build.py includes some Qt-related
messages:
W: no module named PyQt4._qt (top-level import by PyQt4.QtGui)
W: no module named readline (delayed import by pdb)
W: no module named pwd (delayed, conditional import by posixpath)
W: no module named org (top-level import by pickle)
W: no module named posix (delayed, conditional import by iu)
W: no module named PyQt4._qt (top-level import by PyQt4)
W: no module named PyQt4._qt (top-level import by PyQt4.QtCore)

Is this expected to work on the trunk, or should I be using some other
snapshot?
Re: [PyInstaller] Problem with Python 2.6 and PyQt4 on Windows Giovanni Bajo 10/8/10 9:17 AM

No, this is supposed to work. Are you using the standard GPL installer
of PyQt from Riverbank's site or have you built PyQt yourself?
--
Giovanni Bajo   ::  ra...@develer.com
Develer S.r.l.  ::  http://www.develer.com


Re: [PyInstaller] Problem with Python 2.6 and PyQt4 on Windows Nathan Weston 10/8/10 9:40 AM

I'm using the Riverbank installer: PyQt4 GPL v4.7.4 for Python 2.6. I'm
running Windows 7 64-bit, but Python and PyQt are 32-bit.

My program looks like this:
# qthello.py
import sys
import sip
import PyQt4.QtCore
import PyQt4.QtGui

app = PyQt4.QtGui.QApplication(sys.argv)
window = PyQt4.QtGui.QMainWindow()
window.setCentralWidget(PyQt4.QtGui.QLabel("Hello"))
window.show()
sys.exit(app.exec_())
# end of qthello.py

I built it like so:
python Makespec.py qthello.py
python Build.py qthello\qthello.spec

Let me know if there's any other information I can provide.

Re: [PyInstaller] Problem with Python 2.6 and PyQt4 on Windows Raoul Snyman 10/8/10 12:47 PM
On 8 October 2010 18:40, Nathan Weston <elb...@spamcop.net> wrote:
> My program looks like this:
> # qthello.py
> import sys
> import sip
> import PyQt4.QtCore
> import PyQt4.QtGui
>
> app = PyQt4.QtGui.QApplication(sys.argv)
> window = PyQt4.QtGui.QMainWindow()
> window.setCentralWidget(PyQt4.QtGui.QLabel("Hello"))
> window.show()
> sys.exit(app.exec_())
> # end of qthello.py

Your application is incorrect. You have to import PyQt4 like so:

from PyQt4 import QtCore, QtGui

Also, there is no need to import sip.

--
Raoul Snyman
B.Tech Information Technology (Software Engineering)
E-Mail:   raoul....@gmail.com
Web:      http://www.saturnlaboratories.co.za/
Blog:      http://blog.saturnlaboratories.co.za/
Mobile:   082 550 3754
Registered Linux User #333298 (http://counter.li.org)

Re: [PyInstaller] Problem with Python 2.6 and PyQt4 on Windows Nathan Weston 10/8/10 1:10 PM
On 10/8/2010 3:47 PM, Raoul Snyman wrote:
> On 8 October 2010 18:40, Nathan Weston<elb...@spamcop.net>  wrote:
>> My program looks like this:
>> # qthello.py
>> import sys
>> import sip
>> import PyQt4.QtCore
>> import PyQt4.QtGui
>>
>> app = PyQt4.QtGui.QApplication(sys.argv)
>> window = PyQt4.QtGui.QMainWindow()
>> window.setCentralWidget(PyQt4.QtGui.QLabel("Hello"))
>> window.show()
>> sys.exit(app.exec_())
>> # end of qthello.py
>
> Your application is incorrect. You have to import PyQt4 like so:
>
> from PyQt4 import QtCore, QtGui

Thanks, that fixes the problem. But it seems like a stretch to call the
program "incorrect" when it works just fine. Why does PyInstaller
understand one form of import but not the other?

> Also, there is no need to import sip.
>

True. In my real program I'm importing sip to do this:

import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
from PyQt4.QtCore import *
from PyQt4.QtGui import *

Which leads me to another problem. When I package the larger program
with PyInstaller and run the EXE, I get this error:

ValueError: API 'QString' has already been set to version 1

It seems as though PyQt is somehow getting loaded before my sip.setapi
calls, even though I haven't explicitly imported it yet. Again, it works
correctly when I run the .py file directly. Is there a workaround for this?

- Nathan

Re: [PyInstaller] Problem with Python 2.6 and PyQt4 on Windows Martin Zibricky 10/8/10 2:20 PM
Nathan Weston píše v Pá 08. 10. 2010 v 16:10 -0400:

> it works
> correctly when I run the .py file directly. Is there a workaround for
> this?

Yes, it is.

put the following lines somewhere at the top in
file   ./trunk/support/rthooks/pyi_rth_qt4plugins.py

import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)

Re: [PyInstaller] Problem with Python 2.6 and PyQt4 on Windows Giovanni Bajo 10/9/10 3:47 AM
On 10/8/2010 10:10 PM, Nathan Weston wrote:
> On 10/8/2010 3:47 PM, Raoul Snyman wrote:
>> On 8 October 2010 18:40, Nathan Weston<elb...@spamcop.net> wrote:
>>> My program looks like this:
>>> # qthello.py
>>> import sys
>>> import sip
>>> import PyQt4.QtCore
>>> import PyQt4.QtGui
>>>
>>> app = PyQt4.QtGui.QApplication(sys.argv)
>>> window = PyQt4.QtGui.QMainWindow()
>>> window.setCentralWidget(PyQt4.QtGui.QLabel("Hello"))
>>> window.show()
>>> sys.exit(app.exec_())
>>> # end of qthello.py
>>
>> Your application is incorrect. You have to import PyQt4 like so:
>>
>> from PyQt4 import QtCore, QtGui
>
> Thanks, that fixes the problem. But it seems like a stretch to call the
> program "incorrect" when it works just fine. Why does PyInstaller
> understand one form of import but not the other?

No reason, actually, sounds like a bug (though it's hard to believe
since it's a pretty common form of imports). I'll have a look.


--
Giovanni Bajo   ::  ra...@develer.com
Develer S.r.l.  ::  http://www.develer.com