'module' object has no attribute

2,293 views
Skip to first unread message

Jason Huang

unread,
Feb 21, 2018, 10:10:31 AM2/21/18
to Python Programming for Autodesk Maya
Hi all,

I got stuck at the beginning of creating a UI interface and couldn't figure out what was missing.

ENV: Maya 2018 update 2, Windows 10.

script name: assetManager.py (saved in Maya 2018 scripts folder)
from Qt import QtWidgets, QtCore, QtGui
import pymel.core as pm

class ObjectManager(QtWidgets.QDialog):
   
def __init__(self):

       
super(ObjectManager, self).__init__()

def showUI():
    ui
= ObjectManager()
    ui
.show()
   
return ui

In Maya script editor: (python panel)
import assetManager
reload
(assetManager)

ui
= assetManager.showUI()

Maya errors out: 
# Error: AttributeError: file <maya console> line 1: 'module' object has no attribute 'showUI' #

I am following a course and the same code demo-ed in the course video works fine in teacher's Maya session.

Thanks,
Jason

Marcus Ottosson

unread,
Feb 21, 2018, 10:18:40 AM2/21/18
to python_in...@googlegroups.com

Try print(assetManager) to find out where the file actually resides on disk, and make sure it’s the file you expect.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c31b5c6f-15d1-4203-ae10-6eb59dfa2362%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Huang

unread,
Feb 21, 2018, 10:56:32 AM2/21/18
to Python Programming for Autodesk Maya
Thanks Marcus. Just tried that and apparently it's executing from the Maya 2017 scripts folder
print(assetManager)
<module 'assetManager' from 'C:\Users\jason\Documents\maya\2017\scripts\assetManager.pyc'>

If I remove the assetManager.py from Maya 2017 scripts folder, everything is fine.
Is there a way to tell Maya 2018 to execute from the 2018 script folder instead of the 2017?

Marcus Ottosson

unread,
Feb 21, 2018, 11:08:44 AM2/21/18
to python_in...@googlegroups.com

Yes, try something like this.

import sys
sys.path.insert(0, r"C:\Users\jason\Documents\maya\2018\scripts")
import assetManager

sys.path is a list of all directories Python will look for modules, prior to importing it for the first time. It’s a somewhat forceful way of achieving it however, it’s likely something is not right with your setup.

Have a look at what your PYTHONPATH looks like.

import os
print(os.getenv("PYTHONPATH"))

PYTHONPATH (may) contain paths that is eventually parsed into sys.path.

If it contains anything, then that is where Python will look for your modules. Next is having a look at your maya.env file of your user directory, that can safely be empty. If neither of those have any content, then something more murky is happening. Maya should be able to find scripts from its own scripts directory without any interference. If all else fails, remove/move your Documents\maya directory elsewhere, such that Maya can create a new one without any customisations.


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Jason Huang

unread,
Feb 21, 2018, 12:03:26 PM2/21/18
to Python Programming for Autodesk Maya
Thank you for the tips Marcus. As checking the PYTHONPATH, I guess the problem was I have an older version of assetManager.py saved in the 2017 scripts folder and that directory is part of the PYTHONPATH directories Maya will look for modules. Maya 2018 might parse the 2017 scripts directory and execute the older version of assetManager.py first.

cheers,
Jason
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c31b5c6f-15d1-4203-ae10-6eb59dfa2362%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Feb 21, 2018, 12:12:19 PM2/21/18
to python_in...@googlegroups.com

Ah, well you can spot the order in which directories are evaluated by looking at the order of paths in sys.path. You should find that the 2017 folder is before the 2018 folder. This shouldn’t be Maya’s doing, but rather something happening elsewhere. 2018 shouldn’t know about 2017, nor any other version before it.

Ps. I use the word “should” rather than “is” because sometimes Maya simply goes bananas. :)


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Jason Huang

unread,
Feb 21, 2018, 12:31:02 PM2/21/18
to Python Programming for Autodesk Maya
ha...you are right. The 2017 scripts directory indeed shows up in front of the 2018 one based on the order listed. Seems like my Maya 2018 is going a bit bananas... :) 
Now I know what's going on and a solution. Thank you, Marcus!
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

zeth willie

unread,
Feb 21, 2018, 3:43:07 PM2/21/18
to Python Programming for Autodesk Maya
Hey Jason-

I've attached a script that I wrote a while back that may be useful for stuff like this. Put it in your scripts folder (instructions for executing in the header) and it will help manage your python paths (add, remove, reorder). The first tab lets you save/load paths for quickly loading common paths you use, the second tabs show the item in your python path in order and lets you change a few things. Nothing too fancy, but might be helpful for seeing what's going on.
I assume dropping a file here isn't an issue. I'm sure I have it handy online (somewhere other than in a big repo on github) if this doesn't work

Zeth
zbw_appendPath.py

Jason Huang

unread,
Feb 22, 2018, 12:42:39 AM2/22/18
to Python Programming for Autodesk Maya
Hey Zeth, 

Sorry for the late response. Much appreciated for the attached script. It seems to be super handy tool. I am able to download the attachment just fine. Will definitely give that a go and let you know.

cheers,
Jason

Jason Huang

unread,
Feb 23, 2018, 9:18:07 AM2/23/18
to Python Programming for Autodesk Maya
Works like a charm, Zeth. I am able to add, delete, move order of python paths in a nice little GUI. Awesome! Thanks so much!

-Jason


On Wednesday, February 21, 2018 at 12:43:07 PM UTC-8, zeth willie wrote:

zeth willie

unread,
Feb 23, 2018, 9:49:14 AM2/23/18
to Python Programming for Autodesk Maya
glad it helped!
Reply all
Reply to author
Forward
0 new messages