我正在尝试使用 PyQt4 运行一些示例代码。我正在尝试从 Notepad++ 以及 Enthought Canopy 环境中运行它。示例代码如下所示。在 npp 中,我使用插件 nppExec 和python -i "$(FULL_CURRENT_PATH)"作为命令。(我也试过没有交互式-i)
import sys
from PyQt4 import QtGui
def main():
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
当我从 npp 中运行它时,内部控制台似乎冻结(没有错误)并且可以使用 ctrl-c 恢复
当我从 Canopy 中运行它时,我收到以下错误消息
%run "c:\users\brian\appdata\local\temp\tmpfe9mmh.py"
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
C:\Users\Brian\AppData\Local\Enthought\Canopy32\App\appdata\canopy-1.0.0.1160.win-x86\lib\site-packages\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
174 else:
175 filename = fname
--> 176 exec compile(scripttext, filename, 'exec') in glob, loc
177 else:
178 def execfile(fname, *where):
c:\users\brian\appdata\local\temp\tmpfe9mmh.py in <module>()
20
21 import sys
---> 22 from PyQt4 import QtGui
23
24
C:\Users\Brian\AppData\Local\Enthought\Canopy32\App\appdata\canopy-1.0.0.1160.win-x86\lib\site-packages\IPython\external\qt_loaders.pyc in load_module(self, mod_name)
43 Importing %s disabled by IPython, which has
44 already imported an Incompatible QT Binding: %s
---> 45 """ % (mod_name, loaded_api()))
46
47 ID = ImportDenier()
ImportError:
Importing PyQt4 disabled by IPython, which has
already imported an Incompatible QT Binding: pyside
我很困惑为什么 Canopy 将其项目放在一个看似奇怪的地方 (C:\Users\Brian\AppData\Local\Enthought\Canopy32),而不是简单的 C:/python27
我正在运行 python 2.7 32 位,Canopy 版本:1.0.0.1160 32 位,Win7 64 位