Adding Python modules scipy/numpy?

Adding Python modules scipy/numpy?

Anonymous
Not applicable
4,152 Views
5 Replies
Message 1 of 6

Adding Python modules scipy/numpy?

Anonymous
Not applicable

Hello!

 

I'm very new to the Maya API, and I'm trying to write a plugin for Maya 2011 in Python (on OSX 10.8). I'd like to use the libraries scipy and numpy, but Maya's internal Python does not come with these libraries. I downloaded anaconda, and can access the modules from my computer's Python. I've tried adding the packages to the site-packages directory, but I get the following error when I try to import either of them:

 

import numpy
# Error: ImportError: file /Applications/Autodesk/maya2011/Maya 2011.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/numpy/core/__init__.py line 5: dlopen(/Applications/Autodesk/maya2011/Maya 2011.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/numpy/core/multiarray.so, 2): Symbol not found: _PyCapsule_Import
  Referenced from: /Applications/Autodesk/maya2011/Maya 2011.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/numpy/core/multiarray.so

 

I'm not sure what this error means, or if there's any way around it. Any help would be appreciated!

 

 

0 Likes
4,153 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

I believe this is likely because your numpy needs to be rebuilt using the same compiler as mayapy.exe. Which may be problematic. I am also looking for a solution to this issue, in particular for Maya 2013, but if it makes it easier, than maya 2014 info would also be of interest.

 

FYI there is a related post mentioning this issue here: http://forums.autodesk.com/t5/Programming/Beware-Maya-2013-and-Python-Extensions-are-incompatible-un...

 

0 Likes
Message 3 of 6

cyrille
Alumni
Alumni

Hi

 

yamoinca is correct, you need to recompile these modules using the same compiler that Maya uses. which means Visual Studio SP1 for 2013 / 2014 and Visual Studio 2008 SP1 for Maya 2011 - see complete list of compilers here and here.

 

cheers

cyrille

0 Likes
Message 4 of 6

Anonymous
Not applicable
Hello,

I need to use scipy in Maya but I fail to make it work. Is it possible that scipy needs to be recompiled for Maya 2015 as jumpy? Is there any repository with recompiled Python modules so that we can use them in Maya?


Best
0 Likes
Message 5 of 6

cyrille_fauvel
Autodesk
Autodesk

Hi

 

as said above, you need to recompile python modules using the correct compiler and be on the same architecture than your maya host application architecture (x64 vs win32). Unfortunately, there is no repository for precompiled Python module for Maya that I am aware of.

 

0 Likes
Message 6 of 6

skuzee
Participant
Participant

What you need is a full version of Python 2.7 compiled against MSVC2010 from where you can then build python packages with .dll dependencies (like scipy). Luckily, someone has done the hard work of explaining how to do this here. The author goes in lengths discussing the reasons you'd want to do this and the step required to proceed. He also provides you with prebuilt binaries, which is really nice.

 

Once you have a stable MSVC2010 version of python2.7 64 bit running, you should be able to build python wheels with .dll dependencies. The best part of python wheels is that it lets you install a C extension with no compilers needed. So, you can now use your new VS2010 version of pip to install numpy, scipy, and other python packages you want, which should be compatible with mayapy.

 

To save you some work, feel free to go ahead and grab the builds I currently use here.


In there you'll find:
Numpy 1.9.2
Scipy 0.16.0
Numexpr 2.4.3

All tested with Maya 2014 and 2015. I haven't tested on 2016 but I presume it'll work just fine. Also, i added numexpr for everyone to grab as it is speeds things up a lot when doing linear math on very large arrays.

Cheers!

Disclaimer: when i say "All tested", what I really mean is: "it works on my machine" I did notice that both numpy.test() and scipy.test() makes maya (2014) crash, but i've been using all three packages with my toolset for quite a while and never encountered a problem.