Results 1 to 5 of 5

Thread: ImportError: Cannot import name

  1. #1

    Default ImportError: Cannot import name

    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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: ImportError: Cannot import name

    What are the import related lines at the top of the program?

  3. #3

    Default Re: ImportError: Cannot import name

    Thanks for your reply and attempt Guru,

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

    I have:

    Qt Code:
    1. import sys
    2. import numpy as np
    3. from math import *
    4. from PyQt4 import QtCore, QtGui
    5. from integrator import Ui_integrator
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. from PyQt4 import QtCore, QtGui
    2.  
    3. try:
    4. _fromUtf8 = QtCore.QString.fromUtf8
    5. except AttributeError:
    6. _fromUtf8 = lambda s: s
    7.  
    8. class Ui_Integrator(object):
    9. def setupUi(self, Integrator):
    10. Integrator.setObjectName(_fromUtf8("Integrator"))
    11. Integrator.resize(484, 596)
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: ImportError: Cannot import name

    I am not much of a Python jockey, but if your generated pyuic4 output is in file Ui_integrator.py then
    Qt Code:
    1. from Ui_integrator import Ui_integrator
    To copy to clipboard, switch view to plain text mode 
    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.

  5. #5

    Default Re: ImportError: Cannot import name

    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.
    Last edited by wanmonk; 16th December 2013 at 05:36.

Similar Threads

  1. Qt 4.5 import stylesheet
    By dcoppenb in forum Qt Programming
    Replies: 0
    Last Post: 7th March 2013, 12:47
  2. How to import qss into another qss file
    By bedbuffer in forum Newbie
    Replies: 1
    Last Post: 4th April 2011, 11:22
  3. import pdf in a QGraphicsView
    By tilsitt in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2011, 16:18
  4. Import dll problems
    By tom0485 in forum Qt Programming
    Replies: 7
    Last Post: 25th May 2010, 07:47
  5. How do i import and use a DLL like Skype4COM.dll in Qt4?
    By fernando in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2010, 07:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.