PDA

View Full Version : ImportError: Cannot import name



wanmonk
16th December 2013, 04:03
Good nite everyone,
New to the forums here. I am attempting to do several little projects, one being to integrate python into a gui using pyqt4. I'm still quite new and still do not know if i'm doing it right (i'm trying to follow on forums and video tutorials online). When I try to run my python script that i'm assuming should atleast produce the shell of my ui that I created using Qt, I get this error.


ImportError: cannot import name Ui_integrator

i'm a bit confused as I thought I was calling my libraries correctly. I have three files. integrator.py (which is the script I made), integrator.ui which is what I made in Qt and Ui_integrator.py which I created using pyuic4 which are all in the same directory.

Anyone have any ideas? Should I attach my files that I have to make things more clear?

Thanks in advance.

ChrisW67
16th December 2013, 05:17
What are the import related lines at the top of the program?

wanmonk
16th December 2013, 06:07
Thanks for your reply and attempt Guru,

In my integrator.py (this is my python script)

I have:


import sys
import numpy as np
from math import *
from PyQt4 import QtCore, QtGui
from integrator import Ui_integrator

in my Ui_integrator (that I made as a result of my Qt.ui, the first few lines are:


from PyQt4 import QtCore, QtGui

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

class Ui_Integrator(object):
def setupUi(self, Integrator):
Integrator.setObjectName(_fromUtf8("Integrator"))
Integrator.resize(484, 596)

ChrisW67
16th December 2013, 06:17
I am not much of a Python jockey, but if your generated pyuic4 output is in file Ui_integrator.py then


from Ui_integrator import Ui_integrator

seems closer to the mark. The first Ui_integrator (module name) gets mapped to the file Ui_integrator.py, and the second Ui_integrator is the name of the symbol (class in this case) to import.

wanmonk
16th December 2013, 06:36
Thanks for your swift response Chris.

It seems it did not work. You are right though.. the from <module name> import <module> is more or less suppose to work, as that line is Imported from the ui class created by Qt Designer from the Python script created by pyuic4. I'm still working on it, but why I can't seem to get this to work is a head scratcher.

Added after 4 minutes:

I could also post what I have if that helps.