简体   繁体   English

无法运行PyQt4示例

[英]unable to run PyQt4 example

I am trying to run a pyqt4 example through Notepad++. 我正在尝试通过记事本++运行pyqt4示例。 I asked this question earlier ( Nothing happens when running PyQt4 example code ), and ended up uninstalling Enthought Canopy and all remnants of python and installing cygwin. 我早些时候问了这个问题( 运行PyQt4示例代码时什么也没有发生 ),最终卸载了Enthought Canopy和所有python残余并安装了cygwin。 Now, when I run the example code I get the following error from npp's console. 现在,当我运行示例代码时,我从npp的控制台收到以下错误。 nppExec command --> C:\\cygwin\\bin\\python2.7.exe -i "$(FULL_CURRENT_PATH)" . nppExec命令-> C:\\cygwin\\bin\\python2.7.exe -i "$(FULL_CURRENT_PATH)" The example code is shown all the way at the bottom. 示例代码始终显示在底部。

The closest I can get is to start cygwin x (type startx from the bash shell) where I can get the example window to come up, although I am unable to exit out of the window. 我能得到的最接近的是启动cygwin x(从bash shell输入startx),尽管我无法退出该窗口,但可以在该窗口中打开示例窗口。

I feel like I am in over my head here, I just want to create some simple GUI's and I am struggling just to get an example to work. 我感觉自己在这里,我只是想创建一些简单的GUI,而我正努力使示例工作。 Does Cygwin's python installation lack the classic IDLE? Cygwin的python安装缺少经典的IDLE吗?

C:\cygwin\bin\python2.7.exe -i "C:\Users\Brian\Dropbox\Python\PYqt_practice.py"
Process started >>>
cygwin warning:
  MS-DOS style path detected: C:\Users\Brian\Dropbox\Python\PYqt_practice.py
  Preferred POSIX equivalent is: /cygdrive/c/Users/Brian/Dropbox/Python/PYqt_practice.py
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
C:\Users\Brian\Dropbox\Python\PYqt_practice.py: cannot connect to X server 
<<< Process finished. (Exit code 1)
================ READY ================

PyQt4 example code PyQt4示例代码

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()

PyQT4 and PyQT5 installed with Cygwin emulate directly what their equivalent Linux packages do, meaning they do expect you to run an X server. 与Cygwin一起安装的PyQT4和PyQT5直接模拟它们等效的Linux软件包的作用,这意味着它们确实希望您运行X服务器。 Packages dedicated to Windows obviously don't. Windows专用软件包显然没有。

Basically you have two choices: 基本上,您有两种选择:

  1. Give up on Cygwin and use packages dedicated to Windows, that don't need X server. 放弃Cygwin,使用不需要X服务器的Windows专用软件包。 (You could also run non-Cygwin python in Cygwin environment, but that's going to cause you some headaches, for example with Unicode.) (您也可以在Cygwin环境中运行非Cygwin python,但这会给您带来一些麻烦,例如Unicode。)
  2. Install X server for Cygwin like this: 像这样为Cygwin安装X服务器:

    1. Get xorg-server package 获取xorg-server软件包
    2. Run startx 运行startx

    If this causes you problems, try: 如果这导致您遇到问题,请尝试:

    1. Run xwin -multiwindow instead of startx 运行xwin -multiwindow而不是startx

    Now an icon should appear in your tray. 现在,图标应该出现在您的任务栏中。

    1. Click it with right mouse button 用鼠标右键单击它
    2. Hover to "applications" 悬停在“应用程序”上
    3. Click xterm . 单击xterm

    Congratulations! 恭喜你! You just ran an xterm shell in X environment. 您只需在X环境中运行xterm shell。 See if your application works now. 查看您的应用程序现在是否可以运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM