My PyQt app runs fine inside Idle but throws an error when trying to run from cmd
<p>So I'm learning PyQt development and I typed this into a new file inside IDLE:</p>

<pre><code>import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def window():
    app = QApplication(sys.argv)
    win = QDialog()
    b1 = QPushButton(win)
    b1.setText("Button1")
    b1.move(50,20)
    b1.clicked.connect(b1_clicked)

    b2=QPushButton(win)
    b2.setText("Button2")
    b2.move(50,50)
    QObject.connect(b2,SIGNAL("clicked()"),b2_clicked)

    win.setGeometry(100,100,200,100)
    win.setWindowTitle("PyQt")
    win.show()
    sys.exit(app.exec_())

def b1_clicked():
    print("Button 1 clicked")

def b2_clicked():
    print("Button 2 clicked")


if __name__ == '__main__':
    window()
</code></pre>

<p>The app does what is supposed to, which is to open a dialog box with two buttons on it, when run inside IDLE.  When I try to run the same program from cmd I get this message:</p>

<p>Traceback (most recent call last):
  File "C:\Python34\Basic2buttonapp.py", line 2, in 
    from PyQt4.QtCore import *
ImportError: No module named 'PyQt4'</p>

<p>I've already tried typing python.exe inside cmd to see if Im running the correct version of python from within the cmd, but this does not seem to be the problem.  I know it has to do with the communication between python 3.4 and the module, but it seems weird to me that it only happens when trying to run it from cmd.  </p>

<p>If anyone has the solution I'll be very thankful. </p>

<p>This is because when running from the command line you're using a different version of Python to the one in IDLE (with different installed packages). You can find which Python is being used by running the following from the command line:</p>

<pre><code>python -c "import sys;print(sys.executable)"
</code></pre>

<p>...or within IDLE:</p>

<pre><code>import sys
print(sys.executable)
</code></pre>

<p>If those two don't match, there is your problem. To fix it, you need to update your <code>PATH</code> variable to put the <em>parent folder</em> of the Python executable referred to by IDLE at the front. You can get instructions of how to do this on Windows <a href="http://stackoverflow.com/questions/9546324/adding-directory-to-path-environment-variable-in-windows">here</a>.</p>

python cmd pyqt pyqt4 python-3.4