I'm trying to run an app with PySide2
from Spyder 3.2.8
and Python 3.6.4
in Anaconda in a macOS 10.13.4
.
attempt N°1
After having seen this stackoveflow page and this github page I changed my graphic backend from Inline
to Automatic
in Python > Preferences > IPython Console > Graphics
and I tried to run the following script (script N°1):
script N°1
import sys
from PySide2.QtWidgets import *
# Create a Qt application
app = QApplication.instance()
if app is None:
print("print something")
app = QApplication(sys.argv)
# Create a Label and show it
label = QLabel("Hello World")
label.show()
# Enter Qt application main loop
app.exec_()
but got the following error message after running it:
Importing PySide2 disabled by IPython, which has
already imported an Incompatible QT Binding: pyqt5
There are similar reported issues here with matplotlib and here with ipython but it didn't help me (or I couldn't implement it properly). Then I tried to implement the content of this page about qtpy by changing the script N°1 in the following way:
script N°2
import os
os.environ['QT_API'] = 'pyside2'
from qtpy.QtWidgets import *
import sys
# Create a Qt application
app = QApplication.instance()
if app is None:
print("print something")
app = QApplication(sys.argv)
# Create a Label and show it
label = QLabel("Hello World")
label.show()
# Enter Qt application main loop
app.exec_()
attempt N°2
With Inline
selected in Python > Preferences > IPython Console > Graphics
. When I ran the script N°2 , the app launches and I got print something
printed in to the console. When closing the app, I got Out[1]: 0
in the console. However when I run the script again, no error message appears in the console but the window of the app doesn't show-up
attempt N°3
This time with Automatic
selected in Python > Preferences > IPython Console > Graphics
. When I ran the script N°2 the first time, the app didn't launch and I got the following error message
/anaconda3/lib/python3.6/site-packages/qtpy/__init__.py:178: RuntimeWarning: Selected binding "pyside2" could not be found, using "pyqt5"
'using "{}"'.format(initial_api, API), RuntimeWarning)
Out[2]: -1
attempt N°4
With Automatic
selected in Python > Preferences > IPython Console > Graphics
. When I ran the script N°1 after having changed the line from PySide2.QtWidgets import *
to from PyQt5.QtWidgets import *
: The app didn't launch and I got the following error message
Out[1]: -1
attempt N°5
With Inline
selected in Python > Preferences > IPython Console > Graphics
. When I ran the script N°1 after having changed the line from PySide2.QtWidgets import *
to from PyQt5.QtWidgets import *
: The app launches and I got print something
printed in to the console. I closed the app and got Out[1]: 0
in the console. However when I run the script again, no error message appears in the console but the window of the app doesn't show-up
N.B. this question is the continuation of that question