I got a ImportError,help~!

Ian Kelly ian.g.kelly at gmail.com
Wed Nov 24 09:59:33 EST 2010


On 11/24/2010 3:59 AM, xlizzard wrote:
> HI,
> I am a newer to python(my version is 3.1.2),recently I got a IDE named
> Eric(http://eric-ide.python-projects.org/index.html) to study
> and on this main page I downloaded a tutorial named "**minibrowser".
> http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html
> But when I run this source ,I got the follow Error:
> Traceback (most recent call last):
> File "C:\minibrowser\minibrowser\minibrowser.py", line 3, in <module>
> from ui.mainwindow import MainWindow
> File "C:\minibrowser\minibrowser\ui\mainwindow.py", line 10, in <module>
> from Ui_mainwindow import Ui_MainWindow
> ImportError: No module named Ui_mainwindow
> I don't understand what's wrong?!
> The folder structure of the source just like this
> A.py+
> -B.py
> -C.py
> A call B,B call C in the same folder ,and "not found"?
> Can anyone help me,thanks a lot~!

That tutorial was probably written for Python 2.X.  In Python 3, it is 
no longer possible to do relative imports using that syntax.  If you 
change the import line to read:

from .Ui_mainwindow import Ui_MainWindow

or better (making it an absolute import, which is preferred):

from ui.mainwindow.Ui_mainwindow import Ui_MainWindow

then Python will interpret it as a relative import, and it should work. 
  There could still be other incompatibilities due to the version 
difference, however.

Cheers,
Ian




More information about the Python-list mailing list