Qt Designer code not working in another Python script

HI all, recently I am using Qt Designer as a means to create a simple UI then incorporate it into another Python script so as to run it in Maya. Never knew that scripting can do lots of stuff until now…

Anyway, I am using a linux system, having saved all my files in /u/hst/tools/dev/testProject/src
And hence I have 2 files, testProjectUI and testProject

However, currently I am running into some problems and I shall list them below.
This is the codes of my UI that I have created and converted in Qt Designer.

class testProjectUI(object):
    def setupUi(self, TestProject):
        TestProject.setObjectName("TestProject")
        TestProject.resize(410, 636)
        self.ok_pushButton = QtGui.QPushButton(TestProject)
        self.ok_pushButton.setGeometry(QtCore.QRect(200, 600, 98, 27))
        self.ok_pushButton.setObjectName("ok_pushButton")

        self.curItem_lineEdit = QtGui.QLineEdit(TestProject)
        self.curItem_lineEdit.setGeometry(QtCore.QRect(130, 90, 113, 30))
        self.curItem_lineEdit.setObjectName("curItem_lineEdit")
        self.curItem_qLabel = QtGui.QLabel(TestProject)
        self.curItem_qLabel.setGeometry(QtCore.QRect(20, 90, 91, 30))
        self.curItem_qLabel.setObjectName("curItem_qLabel")

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

    def retranslateUi(self, TestProject):
        TestProject.setWindowTitle(QtGui.QApplication.translate("TestProject", "Test Project", None, QtGui.QApplication.UnicodeUTF8))
        self.ok_pushButton.setText(QtGui.QApplication.translate("TestProject", "Ok", None, QtGui.QApplication.UnicodeUTF8))
        self.curItem_qLabel.setText(QtGui.QApplication.translate("TestProject", "Current Shot", None, QtGui.QApplication.UnicodeUTF8))

When I tried running the following command in Maya:

from testProject.src import testProject
win = testProject.TestUi()
win.show()
  1. I was prompted with the error # ImportError: No module named src # when I am running my testProject script where I input in from testProject.src import testProject just before the class function

Am I wrting it wrong?

  1. If I am to add it an object into the curItem_lineEdit as I have named in my UI design, is it right for me to write it as:
Item = 'Trunks'
testProjectUI.curItem_lineEdit.setObjectName(Item)

Many thanks in advance for any answers or advices given!

I am fairly new to scripting myself but,
For starters shouldn’t you do “from testProject.src import testProjectUI” looks like you are trying to import the same file you are running.

If both file are in the src folder you shouldn’t need to specify the folder, this should be enough “from testProjectUI import testProjectUI” (from filename import class)

If you are trying to import a module from a different folder than the script you are running, python needs to know what folders it can import from. (If your testProject file is in the folder testProject and your ui file is in src)
You do this by adding a empty init.py file in the folder you are trying to import from.

If you are trying to run the files in complete different locations you may need to add the paths to the system/environment variables. If you haven’t done it already/before it is done like this in windows:
sys.path.append(’/u/hst/tools/dev/testProject/src’)