Import maya.standalone problem

Hi everyone

i declared the environment variable but still i got problem, i checked sys.path and path is there.
in mayapy.exe everything is working fin and even i make a cube and save it.

this is in python IDEL

>>> import sys
>>> print sys.path
[‘C:\Python26\Lib\idlelib’, 'C:\Program Files\Autodesk\Maya2010\Python\lib\site-packages’, ‘C:\WINDOWS\system32\python26.zip’, ‘C:\Python26\DLLs’, ‘C:\Python26\lib’, ‘C:\Python26\lib\plat-win’, ‘C:\Python26\lib\lib-tk’, ‘C:\Python26’, ‘C:\Python26\lib\site-packages’]

my maya is 2010 and checked mayapy version and is 2.6.1
my python 2.6.6 which is replaced to 2.6.1

this is the error that i got:tear:

>>> import maya.standalone

Traceback (most recent call last):
File “<pyshell#0>”, line 1, in <module>
import maya.standalone
ImportError: DLL load failed: The specified module could not be found.

i check the C:\Program Files\Autodesk\Maya2010\Python\DLLs and there is sqlite3.dll file aswell

please help

To get an external Python interpreter to behave just like the mayapy interpreter, you have do this:


import os
import sys

#====================================================================#
#THESE ARE THE MISSING STUFF WHEN RUNNING python.exe compared with mayapy.exe
#====================================================================#

os.environ["MAYA_LOCATION"] = "C:\Program Files\Autodesk\Maya2011"
os.environ["PYTHONHOME"]    = "C:\Program Files\Autodesk\Maya2011\Python"
os.environ["PATH"] = "C:\\Program Files\\Autodesk\\Maya2011\\bin;" + os.environ["PATH"]

sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\setuptools-0.6c9-py2.6.egg")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\pymel-1.0.0-py2.6.egg")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\ipython-0.10.1-py2.6.egg")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\ply-3.3-py2.6.egg")                         
sys.path.append("C:\Program Files\Autodesk\Maya2011\\bin\python26.zip")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\DLLs")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\plat-win")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\lib-tk")
sys.path.append("C:\Program Files\Autodesk\Maya2011\\bin")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages")


import maya.standalone
maya.standalone.initialize(name='python')

Yes this is for 2011. I tried the same code for 2009 with python 2.5 and it worked flawlessly :). I don’t have 2010 so I couldn’t test it, but all you have to do is switch the 2011s with 2010s :slight_smile:

Hi <b>loneWolf </b>thank you very much, it is working now just a quick question

i check thoes path and there were not folders as plat-win and lib-tk
insted in that lib folder i have got the folder name as tcl8.5 and tk8.5 shall i append them.

sys.path.append(“C:\Program Files\Autodesk\Maya2010\Python\lib\plat-win”)
sys.path.append(“C:\Program Files\Autodesk\Maya2010\Python\lib\lib-tk”)

and
i dont have any of the path below there inside the site-packages is just a maya folder, even i turned on the show
hiden files and non of thoes file was there.

sys.path.append(“C:\Program Files\Autodesk\Maya2010\Python\lib\site-packages\setuptools-0.6c9-py2.6.egg”)
sys.path.append(“C:\Program Files\Autodesk\Maya2010\Python\lib\site-packages\pymel-1.0.0-py2.6.egg”)
sys.path.append(“C:\Program Files\Autodesk\Maya2010\Python\lib\site-packages\ipython-0.10.1-py2.6.egg”)
sys.path.append(“C:\Program Files\Autodesk\Maya2010\Python\lib\site-packages\ply-3.3-py2.6.egg”)

Yeah append those two for safety :slight_smile:

and sorry for those other 4, they are PyMel related stuff which I got by installing so sorry again, you don’t need to include them :smiley:

thank you very much for your help again.

Don’t mention it :slight_smile:

Sorry about bringing this thread back from the dead, but I’m having a related issue that others may be able to shed some light on.

I have added the appropriate paths and environment variables that LoneWolf has mentioned to Python 2.6.4 and Maya standalone (2013) works great for most things. However, when running Maya standalone from this external interpreter I get a fatal error when loading any Python plugin.

Has anyone encountered this before or know of a way to work around this?

Thanks

[QUOTE=cluce;19323]
I have added the appropriate paths and environment variables that LoneWolf has mentioned to Python 2.6.4 and Maya standalone (2013) works great for most things. However, when running Maya standalone from this external interpreter I get a fatal error when loading any Python plugin.

Has anyone encountered this before or know of a way to work around this?

Thanks[/QUOTE]

Same problem here. In Maya standalone, i have a crash when i want to load a python plugin.
Anyone has a solution please ?

[QUOTE=deex;28929]Same problem here. In Maya standalone, i have a crash when i want to load a python plugin.
Anyone has a solution please ?[/QUOTE]

So I’ve not tested this, but I’m going to guess the problem you’re running into is that starting with 2013 Maya’s python has been compiled with a different version of visual studio (hence a new C-runtime) then the standard python interpreter.

This basically means that any compiled libraries could (and often do) cause some major issues. Given that the python plugins all rely on Maya’s compiled libraries its not a stretch to image that this is what causes the breaking.

What you can try doing is using a version python compiled against the same version of visual studio, I’ve found a copy using 2010 which should match Maya2014 Python 2.7.10 with vs2010.

Also I’ve made my own version compiled against vs2012 which should work with 2015 and 2016 Python 2.7.9 with vs2012

Hopefully that all makes sense.

1 Like

^^ This is likely to be the issue. 2013+ uses the 2.7 family, before that it was 2.6. Generally I’ve been able to skate by with binaries that match the major version.

Another example of why binaries are evil :slight_smile: Check out Maya Windows Binaries | RobG3d for Rob G’s list of binaries by version…

1 Like

2013 was actually still 2.6, which is why I don’t have a functioning standalone python to match it (except mayapy.exe). I really didn’t want to try to build my own version when it was that old.
Annoyling python is actually really easy to recompile with the newer runtimes, its the third party things like openssl and sqlite that always cause me the most grief.

[QUOTE=LoneWolf;9380]To get an external Python interpreter to behave just like the mayapy interpreter, you have do this:


import os
import sys

#====================================================================#
#THESE ARE THE MISSING STUFF WHEN RUNNING python.exe compared with mayapy.exe
#====================================================================#

os.environ["MAYA_LOCATION"] = "C:\Program Files\Autodesk\Maya2011"
os.environ["PYTHONHOME"]    = "C:\Program Files\Autodesk\Maya2011\Python"
os.environ["PATH"] = "C:\\Program Files\\Autodesk\\Maya2011\\bin;" + os.environ["PATH"]

sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\setuptools-0.6c9-py2.6.egg")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\pymel-1.0.0-py2.6.egg")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\ipython-0.10.1-py2.6.egg")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\ply-3.3-py2.6.egg")                         
sys.path.append("C:\Program Files\Autodesk\Maya2011\\bin\python26.zip")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\DLLs")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\plat-win")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\lib-tk")
sys.path.append("C:\Program Files\Autodesk\Maya2011\\bin")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python")
sys.path.append("C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages")


import maya.standalone
maya.standalone.initialize(name='python')

Yes this is for 2011. I tried the same code for 2009 with python 2.5 and it worked flawlessly :). I don’t have 2010 so I couldn’t test it, but all you have to do is switch the 2011s with 2010s :)[/QUOTE]

Wondering if anyone else has attempted this with Maya 2016.5 and Maya 2017. Crashing on me when attempting to initialize.

So this won’t work out of the box for any version post 2012, at least on windows.
This is because from 2013 and beyond the Python that ships with Maya is not compiled with the same c-runtime as a standard version of Python.
Which means if you’d like to use a different python interpreter you’ll need to compile it with the same version of visual studio that autodesk has used for the internal version.
In the case of 2016/2017 that would be Visual Studio 2012.

[QUOTE=R.White;30849]So this won’t work out of the box for any version post 2012, at least on windows.
This is because from 2013 and beyond the Python that ships with Maya is not compiled with the same c-runtime as a standard version of Python.
Which means if you’d like to use a different python interpreter you’ll need to compile it with the same version of visual studio that autodesk has used for the internal version.
In the case of 2016/2017 that would be Visual Studio 2012.[/QUOTE]

I can confirm that Maya 2014’s python compiled with Visual Studio 2010 (MSC v.1600) is compatible with the standard Python 2.7.6 build compiled with Visual Studio 2008 (MSC v.1500). 2016/2017 is where the issue for me begins.

I thought this could be one of the causes, but can anyone confirm that a matching re-compile of python does indeed fix it? The documentation for using a different python interpreter is not very encompassing. I could see Autodesk introducing say a new environment variable that could also be a contributing factor.

The whole reason I’m looking into this in the first-place is an issue with running Maya 2016.5’s mayapy.exe through Incredibuild (a network job distribution tool). The executable crashes at the initialization step, without an error message, not unlike when I try to load Maya Standalone through the Python 2.7.6. Thought giving python 2.7.6 a shot instead of mayapy.exe might help me identify the problem, but that clearly comes with its own challenges. Had all this working in 2014 by the way.

I’m surprised you were able to get 2014 to work in a standard interpreter, I had to recompile the whole thing to get it functional.
I’ve also done this for 2015/2016, but I don’t have 2017 installed to see if it works there.

Also you can simplify the needed operations to get standalone to import:


import os
import site

site.addsitedir("C:/Program Files/Autodesk/Maya2016/Python/Lib/site-packages")
os.environ["MAYA_LOCATION"] = "C:/Program Files/Autodesk/Maya2016"
os.environ["PATH"] = "C:/Program Files/Autodesk/Maya2016/bin;" + os.environ["PATH"]

from maya import standalone, cmds
standalone.initialize()

site.addsitedir will take care of any .pth files that might exist, so its a bit easier than manually adding everything to sys.path.

Also just noticed, turns out I compiled 2.7.9 instead of 2.7.6 (which is what 2016 is using) still worked though.

1 Like

Thanks for the info! May be some time before I can get to rebuilding Python, but I’ll give it a go eventually.

Just thought I should followup, the problem I was trying to solve, Maya standalone failing to initialize with Incredibuild, was a problem the Incredibuild developers were able to identify and fix on their end.

So is there no easy fix for this? I mean… to just run a standalone maya from batch via python is proving quite difficult. I can’t get around this:

from maya import standalone, cmds

ImportError: DLL load failed: The specified procedure could not be found.

What version of Maya? And by “via python” do you mean python.exe or are you running this from mayapy.exe?

I’m getting the same error and it looks like standalone is missing from my maya 2020 site-packages (fresh install):