unable to run PyQt4 example
Question: I am trying to run a pyqt4 example through Notepad++. I asked this question
earlier ([Nothing happens when running PyQt4 example
code](http://stackoverflow.com/questions/16380923/nothing-happens-when-
running-pyqt4-example-code)), and ended up uninstalling Enthought Canopy and
all remnants of python and installing cygwin. Now, when I run the example code
I get the following error from npp's console. nppExec command -->
`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.

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. Does Cygwin's python
installation lack the classic 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

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


Answer: PyQT4 and PyQT5 installed with Cygwin emulate directly what their equivalent
Linux packages do, meaning they **do** expect you to run an X server. Packages
dedicated to Windows obviously don't.

Basically you have two choices:

  1. Give up on Cygwin and use packages dedicated to Windows, that don't need X server. (You could also run non-Cygwin python in Cygwin environment, but that's going to cause you some headaches, for example with Unicode.)
  2. Install X server for Cygwin like this:

    1. Get `xorg-server` package
    2. Run `startx`

If this causes you problems, try:

    2. Run `xwin -multiwindow` instead of `startx`

Now an icon should appear in your tray.

    3. Click it with right mouse button
    4. Hover to "applications"
    5. Click `xterm`.

Congratulations! You just ran an `xterm` shell in X environment. See if your
application works now.

