Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

# Error: ImportError: file <maya console> line 1: No module named PySide #

5 REPLIES 5
Reply
Message 1 of 6
amaterasu-qbb
8604 Views, 5 Replies

# Error: ImportError: file <maya console> line 1: No module named PySide #

  1. Are you able to execute this code successfully?
from PySide import QtGui
 
class SingletonType(type):
    _instance = None
          
    def __call__(cls, *args, **kwargs):
        if cls._instance is None:
            cls._instance = super(SingletonType, cls).__call__(*args, **kwargs)
          
        return cls._instance
         
class MainWindow(QtGui.QMainWindow):
    __metaclass__ = SingletonType
     
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        self.setWindowTitle('Singleton Window')
        self.resize(640, 405)

when I run this code the error will show up like this.

# Error: ImportError: file <maya console> line 1: No module named PySide

My pycharm is already getting maya's PySide2, QtGui, QtCore and QtWidgets.

Pyside2Pyside2QtCoreQtCoreQtGuiQtGuiQtWidgetsQtWidgets

 

Labels (2)
5 REPLIES 5
Message 2 of 6
stuzzz
in reply to: amaterasu-qbb

Hi,

 

You may try to import PySide2 instead

Message 3 of 6
amaterasu-qbb
in reply to: stuzzz

Hi! @stuzzz Thanks for the reply.

I tried to import PySide2 like this.

 

 

import PySide2
print('PySide2')

 

 

It shows PySide2 so I think I was able to import it. but when I tried that command in 1 comes error.

 

 

# Error: NameError: file <maya console> line 12: name 'QtGui' is not defined # 

 

 

 so I tried. but come error again.

 

 

import PySide2 
import QtGui


# Error: ImportError: file <maya console> line 2: No module named QtGui # 

 

 

Have you tried the above command? Did it work?

Message 4 of 6
stuzzz
in reply to: amaterasu-qbb

Hi,

 

I rather meant something like this:

from PySide2 import QtGui

 

Message 5 of 6
amaterasu-qbb
in reply to: stuzzz

thank you. I did but its show the error

# Error: AttributeError: file <maya console> line 12: 'module' object has no attribute 'QMainWindow'

I tried two patterns.

 

 

import PySide2 
from PySide2 import QtGui
class SingletonType(type):
    _instance = None
          
    def __call__(cls, *args, **kwargs):
        if cls._instance is None:
            cls._instance = super(SingletonType, cls).__call__(*args, **kwargs)
          
        return cls._instance
         
class MainWindow(QtGui.QMainWindow):
    __metaclass__ = SingletonType
     
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        self.setWindowTitle('Singleton Window')
        self.resize(640, 405)
from PySide2 import QtCore, QtGui, QtWidgets
import maya.cmds as cmds

class SingletonType(type):
    _instance = None
          
    def __call__(cls, *args, **kwargs):
        if cls._instance is None:
            cls._instance = super(SingletonType, cls).__call__(*args, **kwargs)
          
        return cls._instance
         
class MainWindow(QtGui.QMainWindow):
    __metaclass__ = SingletonType
     
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        self.setWindowTitle('Singleton Window')
        self.resize(640, 405)

 

I'm sorry to bother you but could you please try this code?

Message 6 of 6
stuzzz
in reply to: amaterasu-qbb

You've made a mistake here:

 

class MainWindow(QtGui.QMainWindow):
class MainWindow(QtWidgets.QMainWindow):

 Then there is an error concerning your metaclass design. If not sure to know what you try to achieve ...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report