ImportError: cannot import name QtGui or any other PyQt4 module

I´m using PyQt4 with Mac Yosemite 10.10.5. and Python 2.7. When I try to run a simple script using sublime text I get

´ImportError: cannot import name QtGui. 

However when I go into python through the terminal and enter the following line, it seems to accept it.

>>> from PyQt4 import QtGui
>>> 

The script I´m trying to run in Sublime Text is:

import sys


from PyQt4 import QtGui


def main():

    app = QtGui.QApplication(sys.argv)

    w = QtGui.QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Simple')
    w.show()

    sys.exit(app.exec_())


if __name__ == '__main__':
       Main()

My Pyqt4 path is at /Library/Python/2.7/site-packages.

My sys-path output is:

['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Users/cameronmacintyre/Library/Python/2.7/lib/python/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages']

I installed using sip and PyQt4 was installed with the following:

python configure.py -q /usr/bin/qmake-4.8 -d /Library/
Python/2.7/site-packages/ --use-arch x86_64
•
make 
•
sudo make instal

I´ve searched other similar problems for days and can´t find a solution. I´ma bit of a newbie to this, so any help would be appreciated.

ps I did have Python 3 installed for a while but I removed it.

链接地址: http://www.djcxy.com/p/55278.html

上一篇: “ImportError:没有名为硒的模块”

下一篇: ImportError:无法导入名称QtGui或任何其他PyQt4模块