PDA

View Full Version : Maya 2013 and external python packages site


zoharl
08-01-2012, 01:42 PM
As suspected here:

http://forums.cgsociety.org/showthread.php?t=1057487

I think there's an incompatibility issue between mayapy and the standard python. For example I can't import an external package numpy, which I could in maya 2012:

import sys
sys.path.append("/Python26_x64/Lib/site-packages/pymatlab/")
sys.path.append("/Python26_x64/Lib/site-packages/numpy/")
sys.path.append("/Python26_x64/Lib/site-packages/")
sys.path.append("/Python26_x64/Lib/")
sys.path.append("/Python26_x64/Lib/site-packages/numpy/core/")
sys.path.append("/Python26_x64/Lib/site-packages/pymatlab-0.1.3-py2.7.egg-info/")

import site
site.addsitedir("/Python26_x64/Lib/site-packages/pymatlab/")
site.addsitedir("/Python26_x64/Lib/site-packages/numpy/")
site.addsitedir("/Python26_x64/Lib/site-packages/")
site.addsitedir("/Python26_x64/Lib/")

from numpy.random import randn


error:

Traceback (most recent call last):
File "test_pymat_mayapy.py", line 16, in <module>
from numpy.random import randn
File "/Python26_x64/Lib/site-packages/numpy\__init__.py", line 147, in <module
>
import add_newdocs
File "/Python26_x64/Lib/site-packages/numpy\add_newdocs.py", line 9, in <modul
e>
from numpy.lib import add_newdoc
File "/Python26_x64/Lib/site-packages/numpy\lib\__init__.py", line 4, in <modu
le>
from type_check import *
File "/Python26_x64/Lib/site-packages/numpy\lib\type_check.py", line 8, in <mo
dule>
import numpy.core.numeric as _nx
File "/Python26_x64/Lib/site-packages/numpy\core\__init__.py", line 5, in <mod
ule>
import multiarray
ImportError: DLL load failed: The specified module could not be found.

So what did autodesk break up this time?

zoharl
08-02-2012, 11:30 AM
Since maya can't be relied on, and until a solution would be found, I used the following patch.
First I wrote a maya python script that is executed within maya, interacts with it, and get the data for processing. Then the processing step is delegated to an outside python script, which can be executed with any python interpreter. Here is a simple example of a maya script:


import pickle
import subprocess as subp
cmd = "python -E /prj/python/add_one_to_array.py"
a = [1.0, 2.0, 3.0]
p = subp.Popen(cmd, shell=True, bufsize=4096,
stdin=subp.PIPE, stdout=subp.PIPE, stderr=subp.STDOUT)
pickle.dump(a, p.stdin)
p.stdin.close()
b = pickle.load(p.stdout)
#b = p.stdout.read(4096)
print b


and add_one_to_array.py:

import sys
import pickle

a = pickle.load(sys.stdin)
#a = sys.stdin.read(4096)
#print a

for i in xrange(len(a)):
a[i] = a[i] + 1
pickle.dump(a, sys.stdout)

#f = open("/8/out.txt", "w")

sys.stderr.write('Output window\n')


The child stderr is forwarded to the parent stdout, but it doesn't work, although sometimes the error is written to the output window. So if an error is thrown from the child script, instead of pickle.load from the parent do a simple read (as in the commented line).

Joviex
08-03-2012, 08:37 AM
Is this a x64 bit version of 2013 (I assume yes).

Does it work in a x32 bit version? Just curious.

zoharl
08-03-2012, 08:42 AM
Sorry, I don't have the 32bit to test this.

zoharl
08-17-2012, 06:07 AM
Another verification to the problem at hand:

http://forums.cgsociety.org/showthread.php?p=7393148#post7393148
http://grokbase.com/p/python/image-sig/118js6g1e3/help-with-pil-on-64-bit-windows-7-and-maya

CadOp
12-14-2012, 03:02 PM
Yea its BS. I contacted autodesk the week maya 2013 came out and their response to me was that they modified python in a non standard way and I have to compile numpy against maya. Its an issue they know about. It had to do with them wanting to make some of their own math functions.

CGTalk Moderation
12-14-2012, 03:02 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.