SublimeJedi doesn't find my Maya's python stubs

596 views
Skip to first unread message

a

unread,
Jan 3, 2014, 10:22:59 AM1/3/14
to python_in...@googlegroups.com
 
Hi All,  

This is my first post in the forum and I hope someone can help me out here.

I just started coding python in Sublime3, however it seems Sublime can't find my Maya's stubs and also autocompletion is not working. For autocompletion, I have installed SublimeJedi.

Here is a simple script I have:

basic.py

import maya.cmds as cmds
cmds
.polySphere();


and here is the error which suggests sublime can't find my api and cmds folder

ImportError: No module named 'maya'
[Finished in 0.0s with exit code 1]

Followings are all the info you may need to know: 

Sublime Version: 3
Build System: Python 3.4
Installed Packages: SublimeJedi
OSX
: Mavericks
Python Version: Python3.4
Maya Version: Maya2014


My Build setup for Python3.4
Python3.4.sublime-build
{
   
"cmd": ["python3.4", "-u", "$file"],
   
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
   
"selector": "source.python",
   
"encoding": "utf8",
   
"path": "/Library/Frameworks/Python.framework/Versions/3.4/bin/",
}

My project setup 
myproject.sublime-project
{
   
"folders":
   
[
       
{
           
"path": "/Users/hsabri/Library/Preferences/Autodesk/maya/2014-x64/scripts/zepto/basic/"
       
}
   
],
 
   
"settings": {
       
"python_interpreter_path": "/Library/Frameworks/Python.framework/Versions/3.4/bin",
 
       
"python_package_paths": [
           
// My python package path
           
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages",


           
// Maya's python stubs
           
"/Applications/Autodesk/maya2014/devkit/devkit/other/pymel/extras/completion/py/"
           
]
   
}
}


Thanks again,

-h



Ævar Guðmundsson

unread,
Jan 3, 2014, 2:34:18 PM1/3/14
to python_in...@googlegroups.com
What you are trying is well doable, I can help if you can provide a little more detail, starting with pasting the output of your sys.path :

import sys
print [ n for n in sys.path ]

  An indicator for you here is this needs to point at the Maya install to get started, once that is set up you can then set up a socket connection which allows you to have instant feedback in the Maya workspace while you are writing in Sublime.

  Start by pasting into this thread the output of the python command above, along with the location of your Maya install and I'm sure we can get this working.

Justin Israel

unread,
Jan 3, 2014, 3:28:15 PM1/3/14
to python_in...@googlegroups.com
I would be concerned about trying to use Python3.x when your developing for Maya, as Maya is still Python2.x. You would have to make sure to only do things that are Python2.x compatible. And you could run into issues if you are importing code.

Also, how are you executing your code, that you are receiving that error message? Are you trying to run it directly from within Sublime?


--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9b5bac2b-c7a2-43bc-bc1f-951557831bf4%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Ævar Guðmundsson

unread,
Jan 3, 2014, 3:46:18 PM1/3/14
to python_in...@googlegroups.com

Thank you Ævar for respond.

Sure, here is the list of paths in my sys.path:

[...]

As for the Maya path, it is installed in :

/Applications/Autodesk/maya2014

-h
 
Cool, that looks all in order and default so it should be all straightforward, apart from the fact I only have Maya LT installed and am on Windows so I'm going to try to talk you through the process of achieving this rather me being able to send you practical snippets....

  What your are seeing in there are all the default paths which python looks for libraries in, the path where maya.cmds for example is installed is not there, and your error is a simple "I don't know the word you are trying to tell me" since no directory or file within that path exists.

  It's as simple as within your Maya install you will find a directory named maya, and within it cmds, that's your cmds module where you find among other things the ability to create a polyCube as per your example.

Mine is usually within Python\lib\site-packages, 
Windows example:
C:\Program Files\Autodesk\Maya2014\Python\Lib\site-packages
So presumably yours is at:
/Applications/Autodesk/maya2014/Python/Lib/site-packages


There are two ways to go about this

[ The dirty way, not good practice at all but works if you accept it for the hack it is as you are altering the system behaviour ]

import sys
path = '/Applications/Autodesk/maya2014/Python/Lib/site-packages'
sys.path.insert( 0, path ) # The zero puts it in front of all other libraries and it will pick up.

[ And the good way ]
You can add this path into your Sublime project settings, i.e.

myproject.sublime-project
{
    
"folders":
    
[
        
{
            
"path": "/Users/hsabri/Library/Preferences/Autodesk/maya/2014-x64/scripts/zepto/basic/"
        
}
    
],
 
    
"settings": {
        
"python_interpreter_path": "/Library/Frameworks/Python.framework/Versions/3.4/bin",
 
        
"python_package_paths": [
            
// My python package path
            "/Applications/Autodesk/maya2014/Python/Lib/site-packages"


            
// Maya's python stubs
            
"/Applications/Autodesk/maya2014/devkit/devkit/other/pymel/extras/completion/py/"
            
]
    
}
}

  At this point I'd expect your editor to no longer complain about a missing maya module and you should be able to run:

import maya.cmds

  without errors, the error however will appear in your next line:
maya.cmds.polyCube()

 and this is where most people I've met trying this get confused. as there is one more step missing.  In order to make use of a standalone version of Maya you need to initialize it ( think of it as the same thing as opening the UI, the whole thing doesn't exist until that's taken place )

Close your editor and restart it, if you have imported maya.cmds without this part it most likely will not pick up if you try again, try this once you've restarted Sublime:

import maya.standalone
maya.standalone.initialize( 'python' )
import maya.cmds
maya.cmds.polyCube()

  The standalone libraries are installed alongside the cmds module and as long as you have a fully licensed copy of Maya this will pull only a batch license as far as I'm aware of.

  I assume you then run the code by simply selecting Tools > Build which runs your code and initializes the library each time?  ( more proper is to make your file executable but that trick works for quick dev at your own risk of course.. )

p.s. As Justin mentions don't use python 3.3 with Maya 2014, it kinda gives the impression that it works most of the time but you will get into some seriously interesting debug sessions, stick with what Autodesk provide.

  Let us know how you get on, the 4 lines above along with your Sublime config should be enough to get this going ( up to the auto completion part at least but it sounds like you have that covered. )


Ævar Guðmundsson

unread,
Jan 4, 2014, 7:30:03 AM1/4/14
to python_in...@googlegroups.com

In case it helps, here are some links showing how to get this working in Sublime 2 using Justin's mayaSublime package and further information


  It’s a tutorial on how to get this going, using Justin’s mayaSublime package.

  And it goes into the socket connection as well so you should be well on your way once you’ve read all this and that, the actual auto-completion referred in the tutorial is this package I believe:

  Not sure if any of that stuff has been tested on Python 3 but for experimentation sake I’d be interested to see how you get on with it.
Reply all
Reply to author
Forward
0 new messages