python窗体应用程序错误_python - 无法在Spyder中看到由PySide2创建的应用程序窗口 - 堆栈内存溢出...

我正在尝试使用Spyder 3.2.8 PySide2和macOS 10.13.4中的Anaconda中的Python 3.6.4运行应用程序。

尝试N°1

在看过这个stackoveflow页面和这个github页面后,我在Python > Preferences > IPython Console > Graphics中将我的图形后端从Inline更改为Automatic ,我尝试运行以下脚本( 脚本N°1 ):

脚本编号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_()

但运行后收到以下错误消息:

Importing PySide2 disabled by IPython, which has

already imported an Incompatible QT Binding: pyqt5

这里有类似的matplotlib报告问题, 这里有ipython,但它没有帮助我(或者我无法正确实现)。 然后我尝试通过以下方式更改脚本N°1来实现此页面关于qtpy的内容:

脚本编号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_()

尝试N°2

在Python > Preferences > IPython Console > Graphics选择Inline 。 当我运行N°2的脚本时 ,应用程序启动,我将print something打印到控制台。 关闭应用程序时,我在控制台中Out[1]: 0 。 但是,当我再次运行脚本时,控制台中不会显示任何错误消息,但应用程序的窗口不会显示

尝试N°3

这次在Python > Preferences > IPython Console > Graphics选择了Automatic 。 当我第一次运行N°2脚本时,应用程序没有启动,我收到以下错误消息

/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

尝试N°4

在Python > Preferences > IPython Console > Graphics选择Automatic 。 当我从PySide2.QtWidgets import *到from PyQt5.QtWidgets import *之后我运行脚本N°1 from PyQt5.QtWidgets import * :应用程序没有启动,我收到以下错误消息

Out[1]: -1

尝试N°5

在Python > Preferences > IPython Console > Graphics选择Inline 。 当我从PySide2.QtWidgets import *到from PyQt5.QtWidgets import *之后我运行了脚本N°1 from PyQt5.QtWidgets import * :应用程序启动并且我print something打印到控制台的内容。 我关闭了应用程序并在控制台中Out[1]: 0 。 但是,当我再次运行脚本时,控制台中不会显示任何错误消息,但应用程序的窗口不会显示

NB这个问题的延续了这个问题