Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Eric - "No module named MainWindow"

1,352 views
Skip to first unread message

Phil

unread,
Feb 17, 2013, 4:08:22 AM2/17/13
to pytho...@python.org
Thank you for reading this.

I've been playing with Eric all day and I almost have a working GUI
application, but not quite. I have followed the two tutorials on the
Eric site and I'm sure that I haven't miss entered anything and so I
think the error is the result of something missing from my system or
perhaps a path error.

This is the error message:

The debugged program raised the exception unhandled ImportError
"No module named MainWindow"
File: /home/phil/main.py, Line: 4

And this is the code:

!/usr/bin/python

from PyQt4.QtGui import QApplication
from ui.MainWindow import MainWindow

def main():
import sys
app = QApplication(sys.argv)
wnd = MainWindow()
wnd.show()
sys.exit(app.exec_())

if __name__ == '__main__':
main()

I have tried mainWindow and mainwindow as well so it appears not to be a
case error.

--
Regards,
Phil

Vincent Vande Vyvre

unread,
Feb 17, 2013, 6:35:33 AM2/17/13
to pytho...@python.org
Le 17/02/13 10:08, Phil a écrit :
Are you sure you have a class MainWindow in your ui.MainWindow.py ?

Can you show us the code of this MainWindow ?

--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>

Joel Goldstick

unread,
Feb 17, 2013, 10:13:56 AM2/17/13
to Vincent Vande Vyvre, pytho...@python.org
I just looked at the tutorial that you might be experimenting with on this page: http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html

The class MainWindow is in mainwindow.py in the ui folder.  I would try this:

from ui.mainwindow import MainWindow




Vincent Vande Vyvre

unread,
Feb 17, 2013, 11:06:24 AM2/17/13
to Joel Goldstick, pytho...@python.org
Le 17/02/13 16:13, Joel Goldstick a écrit :
>
>
>
> On Sun, Feb 17, 2013 at 6:35 AM, Vincent Vande Vyvre
> <vincent.v...@swing.be <mailto:vincent.v...@swing.be>> wrote:
>
> Le 17/02/13 10:08, Phil a écrit :
> > Thank you for reading this.
> >
> > I've been playing with Eric all day and I almost have a working GUI
> > application, but not quite. I have followed the two tutorials on the
> > Eric site and I'm sure that I haven't miss entered anything and so I
> > think the error is the result of something missing from my system or
> > perhaps a path error.
> >
> > This is the error message:
> >
> > The debugged program raised the exception unhandled ImportError
> > "No module named MainWindow"
> > File: /home/phil/main.py, Line: 4
> >
> > And this is the code:
> >
> > !/usr/bin/python
> >
> > from PyQt4.QtGui import QApplication
> > from ui.MainWindow import MainWindow
>

> (strip)
>
>
> I just looked at the tutorial that you might be experimenting with on
> this page:
> http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html
>
> The class MainWindow is in mainwindow.py in the ui folder. I would
> try this:
>
> from ui.mainwindow import MainWindow

In your initial code, thi's "ui.MainWindow" not "ui.mainwindow"

Phil

unread,
Feb 17, 2013, 6:04:23 PM2/17/13
to pytho...@python.org
On 17/02/13 21:35, Vincent Vande Vyvre wrote:
> Le 17/02/13 10:08, Phil a �crit :
>> Thank you for reading this.
>>
>> I've been playing with Eric all day and I almost have a working GUI
>> application, but not quite. I have followed the two tutorials on the
>> Eric site and I'm sure that I haven't miss entered anything and so I
<cut>


> Are you sure you have a class MainWindow in your ui.MainWindow.py ?
>
> Can you show us the code of this MainWindow ?

Thank you Vincent and Joel. I think I have already tried every
conceivable combination but I still cannot get past the error message.
At the risk of burdening the list with lots of code I have decided to
show the code as it stands. It's substantially that from the mini
browser example.

This is the auto generated code for Ui_mainWindow.py:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file
'/home/phil/mainWindow.ui'
#
# Created: Sun Feb 17 15:54:33 2013
# by: PyQt4 UI code generator 4.9.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(200, 200)
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.pushButton = QtGui.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(40, 120, 91, 24))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
MainWindow.setCentralWidget(self.centralWidget)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):

MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",
"MainWindow", None, QtGui.QApplication.UnicodeUTF8))

self.pushButton.setText(QtGui.QApplication.translate("MainWindow",
"PushButton", None, QtGui.QApplication.UnicodeUTF8))


if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

This is the code for mainWindow.py"

class MainWindow(QMainWindow, Ui_MainWindow):
"""
Class documentation goes here.
"""
def __init__(self, parent = None):
"""
Constructor
"""
QMainWindow.__init__(self, parent)
self.setupUi(self)

And this is the main script that I had originally used and named new_gui.py:

from PyQt4 import QtCore, QtGui
from ui.MainWindow import MainWindow

if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
ui = MainWindow()
ui.show()
sys.exit(app.exec_())

Finally, for completeness, this is the error message when I attempt to
execute new_gui.py:

The debugged program raised the exception unhandled ImportError
"No module named mainWindow"
File: /home/phil/new_gui.py, Line: 2

Could it simply be a case of conflict between my file names and the
module name?

--
Regards,
Phil

Phil

unread,
Feb 17, 2013, 10:47:24 PM2/17/13
to pytho...@python.org
On 17/02/13 21:35, Vincent Vande Vyvre wrote:
> Le 17/02/13 10:08, Phil a �crit :
>> Thank you for reading this.
>>
>> I've been playing with Eric all day and I almost have a working GUI
>> application, but not quite. I have followed the two tutorials on the
>> Eric site and I'm sure that I haven't miss entered anything and so I
>> think the error is the result of something missing from my system or
>> perhaps a path error.
>>
>> This is the error message:
>>
>> The debugged program raised the exception unhandled ImportError
>> "No module named MainWindow"
>> File: /home/phil/main.py, Line: 4
>>

The solution is to save the various files in their correct directories
as mentioned in the tutorial.

--
Regards,
Phil

Vincent Vande Vyvre

unread,
Feb 18, 2013, 3:07:06 AM2/18/13
to pytho...@python.org
Le 18/02/13 00:04, Phil a écrit :
> ...
>
> from PyQt4 import QtCore, QtGui
> from ui.MainWindow import MainWindow
>
As I've sayed in my last post, this is not "ui.MainWindow" but

Phil

unread,
Feb 18, 2013, 5:32:30 AM2/18/13
to pytho...@python.org
On 18/02/13 18:07, Vincent Vande Vyvre wrote:
> Le 18/02/13 00:04, Phil a �crit :
>> ...
>>
>> from PyQt4 import QtCore, QtGui
>> from ui.MainWindow import MainWindow
>>
> As I've sayed in my last post, this is not "ui.MainWindow" but
> "ui.mainwindow"
>

Thanks again Vincent,

Your answer is correct but that wasn't the only problem. Anyway, as I
said in my previous message, it works now and I'm pleased that I have
advanced a little with pyqt4.

--
Regards,
Phil
0 new messages