Maya 2008 ext 2, Vista x64, Python woes

Hi everyone,

Have to say after being directed to this forum a month ago, I was more than a little surprised Tech Artists talking to each other so openly about their processes and preferences when tackling problems - this is certainly something I’ve missed during my years in the games industry as full-time artist, part-time scripter. But this could stem from the fact few people at my company know about scripting, aside from copying the contents of the script editor :wink:

I’ve been spurred on recently by the many posts here about using Python as an environment to launch applications and manipulate say, Photoshop documents and cross communication with Maya which is perfect for a tool I wish to write for my fellow artists at my company. But alas, I’ve hit a wall: How do I get Python working in the first place? I’ve found the Maya documention regarding external Python interpreters a little hard to follow.

I’m running Vista x64, Maya 2008 x64 extension 2. But I will have to install this environment on XP x86 too as the other artists are using that. I understand Maya 2008 has Python 2.4, but win32com (2.4, 32bit) won’t install as it can’t detect a Python 2.4 entry in the registry. Will I need to edit this entry myself?

If I install say, Python 2.5.2, win32com (2.5) installs fine without problems, but then I need to set up the system paths, that is:

PATH (C:\Python25)
PYTHONPATH (C:\Python25 and C:\Python25\Lib\site-packages) <- do I really need that second string?
MAYA_LOCATION (C:\Program Files\Autodesk\Maya2008) <- this is 64bit Maya

From a DOS prompt, I can launch the python console (">>>") with “python”.

The next step, “import maya.standalone” appears to do something (whatever it is, the Python console doesn’t provide feedback). And" maya.standalone.initialize( name=‘python’ )" appears to do more stuff but again, no feedback. According to the Maya documentation, it’s meant to launch Maya in a similar way to “batch mode”. But I don’t see a Maya window or process. Clearly I’ve missed a step.

If I launch Maya manually and in the Python script editor type:

import win32com.client

I get this response, which could be due to Maya pointing at its own Python 2.4 implementation:

Error: No module named win32com.client

Traceback (most recent call last):

File “<maya console>”, line 1, in <module>

ImportError: No module named win32com.client

I know this is a lot of questions, but I would appreciate any insight into where I’m going wrong here.

Kind regards,

Wai-Hung

Okay, so I’ve resorted to installing Python 2.5.2, win32com, stuck the relevant paths into the various environment variables, but the hacky way I’m working now is from Maya MEL script:

system (“start c:/python25/python C:/Users/wwan/Documents/maya/2008-x64/python/quickie.py”)

I’m sure this is a particularly bad way to force Maya to open Phototshop and work its magic, but it’s all I have to work with for now.

All I’m trying to do is have the artist create some texture assets via Maya, export them out and then automate Photoshop to create blends and various masks. Then pass the resulting file back to Maya.

Anyone able to suggest a cleaner way than wrapping my Python script around MEL?

I’d think the most proper way would probably be your first inclination, using COM.

That “No module named win32com.client” error means it literally can’t find that module on your Python’s list of system paths.

Now, note that Maya comes with it’s own embedded Python interpreter with it’s own environment. It will generally not know or care about about any external Python installations you have, or any extension packages you’ve installed on those.

I don’t have your exact configuration, so I’m speculating a bit here… But, in theory, you may be able to just add the appropriate package paths to Maya’s Python sys.path list. To look at that current list, run this in your Maya Python window:

import sys
sys.path

That will print out a list of paths it looks on when importing a module. Then do the same in IDLE or a command prompt for your standalone Python installation. You may then be able to do “sys.path.append(‘wherever’)” in Maya to get it to search where you need it to on import.

Another issue you may face is that your standalone Python install is 32-bit, while Maya’s Python is probably 64. Even if the paths are sorted out, the 32-bit pywin32 package will not work in a 64-bit build of Python.

As far as I know, they haven’t released a 64-bit build of pywin32 yet. Although you might look in the Sourceforge forums, I think someone’s been working on that, at least unofficially.

Hi Adam,

Thank you for your reply. I’ve tried your suggestion on both Maya 2008-32 and 64bit, running Python 2.6-32 and win32com-32.

For simplicity, this is what I did on Maya 2008-32bit only. I did a sys.path and replaced all references to Maya’s own Python paths to the Python 2.6 folder:


sys.path.append ('C:\\Python26')
sys.path.append ('C:\\Python26\\DLLs')
sys.path.append ('C:\\Python26\\lib')
sys.path.append ('C:\\Python26\\lib\\plat-win')
sys.path.append ('C:\\Python26\\lib\\lib-tk')
sys.path.append ('C:\\Python26\\lib\\site-packages')

Performing an “import win32com.client” at this point results in:


# Error: No module named win32api
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File "C:/Python26/lib/site-packages\win32com\__init__.py", line 5, in <module>
#     import win32api, sys, os
# ImportError: No module named win32api # 

Now if I:


sys.path.append ('C:\\Python26\\Lib\\site-packages\\isapi\	est\\build\\bdist.win32\\winexe\	emp')

and try “import win32com.client”, I get:


# Error: DLL load failed: The specified module could not be found.
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File "C:/Python26/lib/site-packages\win32com\__init__.py", line 5, in <module>
#     import win32api, sys, os
#   File "C:\Python26\Lib\site-packages\isapi	est\build\bdist.win32\winexe	emp\win32api.py", line 12, in <module>
#     __load()
#   File "C:\Python26\Lib\site-packages\isapi	est\build\bdist.win32\winexe	emp\win32api.py", line 10, in __load
#     mod = imp.load_dynamic(__name__, path)
# ImportError: DLL load failed: The specified module could not be found. # 

I’ve taken another look at the Maya documentation regarding external interpreters and have set the following system environment variables:

MAYA_LOCATION
C:\Program Files (x86)\Autodesk\Maya2008; C:\Program Files\Autodesk\Maya2008

PYTHONPATH
C:\Python26\Lib\site-packages

These again result in “Error: No module named win32api”

Now I’m completely at a loss. :?:

It would appear the Maya documentation left out some rather important details regarding running other Python versions from within Maya:

The win32com (pywin32-212.win32-py2.6) has to be copied into the Maya/Python/Lib/Site-Packages folder.

So:

  1. Install Python 2.6 to C:\Python26
  2. Install pywin32-212.win32-py2.6
  3. Copy the contents of C:\Python26\Lib\Site-Packages into Maya\Python\Lib\Site-Packages.

Now “import win32com.client” works as it should. Phew! Sadly, this only works with Maya 32-bit as you’ve already stated, Maya 64-bit just reports “DLL load failed with error code 193”. Which is odd as the python26.dll, pythoncom26.dll and pywintypes26.dll reside in “C:\Windows\sysWOW64”

Cool, glad you figured it out!

Hey whw,
Seems like you are going through same trouble as I did…
Window’s sysWOW64 is I believe where they store 32bit system related stuff, and very misleadingly, they stores 64bit related stuff under system32 directory.

I installed 64bit version of python and 64bit version of win32 module I found somewhere in the internet.
I was able to use win32 functions from Maya by appending system path to win32 related directory within python25.
But there are so many other module which are not 64bit ready, or have to go through compiling mess.
I haven’t had much luck with it to be honest, one thing I miss is maya.standalone.
It just seems to not work.

Well, hope it works out for you.
Cheers

Hi YutaA,

Yeah, it’s all a little confusing for me as a newbie to Python. Gotta start somewhere :wink:

Like you say, as win32com isn’t 64-bit ready, I’ve now had to rely completely on Maya 2008-32bit. Not a big deal tbh. I’m just happy I’ve got over this hurdle and can now focus on learning the Python environment.

Of course, my next step is figuring out how to code in Python to pass on functions to Photoshop - I’ve located the ScriptListener.8li for Photoshop, but translating from VB and JavaScript isn’t as easy as I thought it would be. Heh… Just knowing MEL was far simpler :laugh:

regards,

/W

Good luck with the photoshop scripting!
I did the same while ago and it wasn’t very straight forward :frowning:
Especially when 3rd party plug-in gets involved.

Regards,
YutaA

I’m not familiar with the ScriptListener plugin, but my blog on Python + Photoshop might help if you want to try it with COM.

http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html

Hi Adam,

I have taken a look at your article, thank you :slight_smile: In fact, it’s one that appears to be well linked when searching for Photoshop and Python.

What I have so far is Photoshop opening and can load and manipulate one document:


psApp.Open(r"C:\TruSim\chisel.bmp")
doc1 = psApp.Application.ActiveDocument
layer1 = doc1.ArtLayers[0] 
layer1.Copy()
doc1.Paste()

With two documents, I have the problem of the second document being in front so I can’t copy from the first document:


psApp.Open(r"C:\TruSim\chisel.bmp")
doc1 = psApp.Application.ActiveDocument
psApp.Open(r"C:\TruSim
oise.bmp")
doc2 = psApp.Application.ActiveDocument
layer1 = doc1.ArtLayers[0] 
layer1.Copy()
doc1.Paste()

At this point, the script breaks at “layer1.Copy()”, with:

“The requested action requires that the target document is the frontmost document.”

How do I bring the first document forward? The Photoshop VB Reference Guide has nothing about making a document the active one.

/W

Problem solved! :smiley:


psApp.Application.ActiveDocument = doc1

/my head hurts

there are four kinds of jewelry,wholesale jewelry,fashion jewelry,handmade jewelry and costume jewelry ,which one do you like ?

Hey Everyone,

with whw’s kind help I’ve been able to call Photoshop from Maya. I’m also able to create a new Layer and rename it. Very nice so far but when I want to make that Layer a TextLayer I have to do the following:

myNewLayer.kind = LayerKind.TEXT

If I get it right, there’s some constant that I get via LayerKind.TEXT and assign it to the kind of the newly created layer. How can I teach Python what these constants are? Up until now Python always says that LayerKind is not defined.
Is it possible to import LayerKind’s content into my script so I can access TEXT?

Thanks for your help. I’m pretty excited about the whole Maya-Photoshop-thing and hope that it is as powerful as I think it is… Without those constants our possibilities are pretty limited, right?

Greetz from Germany,

Matti.

edit:

Can’t figure this out this late but for anyone who’s interested:
The Photoshop Scripting Reference for VB lists all the constants. PsLayerKind is one of them. And here is information about importing constants with Python:
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html

Will have a look at it as soon as I have time to do so… If one of you have a good idea please let me know! :slight_smile:

Ok, I got it. Sry for the multi-posts and my questions :wink:

If anyone is interested in how to do it please ask. I don’t want to write it all down with noone reading it :slight_smile:

beliesafbelierbartbautperacyautism

[QUOTE=YutaA;1598]

I installed 64bit version of python and 64bit version of win32 module I found somewhere in the internet.

[/QUOTE]
Sorry for bringing up a dead thread guys.

Can you please point to where we can find this 64bit version win32 for python 2.5 please. :wink:

Thanks

The pywin32 releases are here:

Although there is no 64 build for Python 2.5. Starting with 2.6 they made building python binaries much easier on Windows, and compatible with Visual Studio 2008.

There may be a way to build pywin32 for Python 2.5 64-bit yourself, but it would take some searching and more than a little elbow grease, I imagine.

I was hoping to find someone that has a compiled copy since I know Softimage compiled a version for XSI for both python 2.4 and 2.5, but Autodesk deleted all those files from the server after the acquisition :(:

I am not a fan of reinventing the wheel, but if all the 64bit files are property of studios then I guess I will have to get dirty and compile one myself.

Yet another dead thread from grave…

but has anyone can point out what is the current situation with 64bit python com programming? Especially to do with 64bit version of pywin32.

I am not sure, but what is the reason for the lack of 64bit version of the pywin extension?

If pywin 64bit version is out of question for some reason. (can’t be publically distributed etc) then what are the alternatives? Anyone?