QtCore.QString can't be imported in Spyder since 2.3.1

1,433 views
Skip to first unread message

Joel Östblom

unread,
Oct 2, 2014, 3:27:08 PM10/2/14
to spyd...@googlegroups.com
HI,

I am not sure I should report this as a bug so checking here first if I am doing something wrong.

The following import fails for me since upgrading to Spyder 2.3.1:

from PyQt4.QtCore import QString

"ImportError: cannot import name QString"

I upgraded Spyder via Anaconda when they recently released a new version (which did not update PyQt). I was going to report this problem on their forum first, but then I tried importing from ipython and ipython qtconsole when launched directly from terminal and the imports work fine in these cases.

The Spyder ipython interpreter reports the same version of the Python and the Qt packages as when I launch ipython/ipython qtconsole from terminal:

Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Aug 21 2014, 18:22:21)
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

from PyQt4.QtCore import QT_VERSION_STR
from PyQt4.Qt import PYQT_VERSION_STR
from sip import SIP_VERSION_STR
print("Qt version:", QT_VERSION_STR)
print("SIP version:", SIP_VERSION_STR)
print("PyQt version:", PYQT_VERSION_STR)

('Qt version:', '4.8.5')
('SIP version:', '4.15.5')
('PyQt version:', '4.10.4')

So I am thinking that Spyder 2.3.1 modifies some setting with the PyQt libraries as they are imported, but I can't detect which one. Any help greatly appreciated.

Cheers,
Joel







Adrian Klaver

unread,
Oct 2, 2014, 5:04:01 PM10/2/14
to spyd...@googlegroups.com
I would start by going to Preferences-->IPython console-->Startup and
see if anything has been added to Run code or Run a file.

>
> Cheers,
> Joel
>

--
Adrian Klaver
adrian...@aklaver.com

Joseph Martinot-Lagarde

unread,
Oct 2, 2014, 5:53:03 PM10/2/14
to spyd...@googlegroups.com
Le 02/10/2014 21:27, Joel Östblom a écrit :
> HI,
>
> I am not sure I should report this as a bug so checking here first if I
> am doing something wrong.
>
> The following import fails for me since upgrading to Spyder 2.3.1:
>
> |
> fromPyQt4.QtCoreimportQString
>
> "ImportError: cannot import name QString"
> |
>
> I upgraded Spyder via Anaconda when they recently released a new version
> (which did not update PyQt). I was going to report this problem on their
> forum first, but then I tried importing from ipython and ipython
> qtconsole when launched directly from terminal and the imports work fine
> in these cases.
>
> The Spyder ipython interpreter reports the same version of the Python
> and the Qt packages as when I launch ipython/ipython qtconsole from
> terminal:
>
> Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Aug 21 2014, 18:22:21)
> Type "copyright", "credits" or "license" for more information.
>
> IPython 2.2.0 -- An enhanced Interactive Python.
> Anaconda is brought to you by Continuum Analytics.
> Please check out: http://continuum.io/thanks and https://binstar.org
> ? -> Introduction and overview of IPython's features.
> %quickref -> Quick reference.
> help -> Python's own help system.
> object? -> Details about 'object', use 'object??' for extra details.
>
> |
> fromPyQt4.QtCoreimportQT_VERSION_STR
> fromPyQt4.QtimportPYQT_VERSION_STR
> fromsip importSIP_VERSION_STR
> print("Qt version:",QT_VERSION_STR)
> print("SIP version:",SIP_VERSION_STR)
> print("PyQt version:",PYQT_VERSION_STR)
>
> ('Qt version:','4.8.5')
> ('SIP version:','4.15.5')
> ('PyQt version:','4.10.4')
> |
>
> So I am thinking that Spyder 2.3.1 modifies some setting with the PyQt
> libraries as they are imported, but I can't detect which one. Any help
> greatly appreciated.
>
> Cheers,
> Joel
When using PyQt API v2, QStrings are automatically transformed into
python strings. This is the default in python3. You can change this
setting in the preferences.

See http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html

Joel Östblom

unread,
Oct 2, 2014, 8:06:57 PM10/2/14
to spyd...@googlegroups.com, joseph.mart...@m4x.org
Thanks for the responses.

There is nothing added to the startup line of the IPython console.

At first, I also thought the issue was in the PyQt Api, but both the IPython interpreter launched from the terminal and the one in Spyder throws the same error when I try to change the api.
 
import sip
sip
.setapi('QString', 1)

"ValueError: API 'QString' has already been set to version 2"

So they both seem to be running with the same setting, but still elicit different behaviours.

Joel Östblom

unread,
Oct 3, 2014, 1:53:35 PM10/3/14
to spyd...@googlegroups.com, joseph.mart...@m4x.org
For now, I just fixed this with a few try/except statements and simply leaving out the QString part in some of them and replacing it with "str()" in others. I would still be interested in why this is happening and if there was anything not in the change notes in the latest Spyder version, but at least everything is working fine again now.
Reply all
Reply to author
Forward
0 new messages