Many Machine Learning libraries support a Python interface. Many DCC applications support Python. But you will often find that these DCC applications and software libraries don’t have binary compatibility. Here is how to solve this problem in Maya for Windows.
If you just want to download our Maya compatible Python libraries, here they are
Python in 3D and Machine Learning
Python is the standard scripting language in the VFX and Animation industries. All prominent DCC applications like Maya, Houdini, C4D, Modo, and Nuke support it.
Python is also the standard in the Machine Learning and Data Science fields. According to this Kaggle survey (https://www.kaggle.com/surveys/2017) 76% professionals in these fields use Python at work. In practicality, that means many Machine Learning frameworks have some Python interface.
These frameworks don’t perform the training of ML models inside Python. They do such computations in C++ code running on the CPU or in CUDA/OpenCL code running on the GPU. But, they use Python as an interface for data manipulation and model configuration.
From this overlap, one would expect Machine Learning libraries to be readily available in software like Maya, through Python. But that is not the case. In this article, I’ll explain why and how to overcome this.
Python version
Maya and many VFX and Animation software have chosen to not upgrade from Python 2 to Python 3. Apart from a few exceptions, most DCC applications come with some version of Python 2.7. But in the Machine Learning field, some prominent players, like Google, have chosen to drop support for these legacy versions of Python.
TensorFlow (Google) and PyTorch (Facebook/Uber/Others), arguably the most prominent ML libraries don’t support Python 3.0, at least on Windows. So, they are a no-go unless you access them through C++.
We are left then with alternatives like Theano, CNTK, and other libraries.
Binary compatibility
But problems don’t end there. Meet binary compatibility
Since these ML libraries perform their computation outside Python, their Python packages are not pure and are composed, in part, of compiled code. Standard Python 2 packages for Windows are compiled with Microsoft’s Visual Studio 2008. But Maya’s Python interpreter is compiled in whatever version of Visual Studio Maya was compiled.
You can attest this by running a standard Python install and then running your Maya20**\bin\mayapy.exe interpreter. Note that MSC v.1*** is the compiler used for that interpreter. In Linux, you would get something like GCC 4.*.*.
Different versions of Visual Studio compile code that is incompatible with each other. That means most of these libraries, in fact, most of their dependencies will crash when you try to run them through Maya.
Solving binary compatibility
So, if you want to run any of these libraries, you will probably need to build many of their dependencies from source using the appropriate version of Visual Studio for your Maya installation. Here is a list:
- Maya 2013-2014 – Visual Studio 2010 (MSC v.1600)
- Maya 2015-2017 – Visual Studio 2012 (MSC v.1700)
- Maya 2018 – Visual Studio 2015 (MSC v.1900)
After installing the appropriate version of Visual Studio, you’ll need to download the libraries from their GitHub repos. Just Google for Github repo and the name of the library. Here is Numpy’s repo as an example (https://github.com/numpy/numpy).
After that, you will need to run the repo’s setup.py in build mode, so it builds a version of the repo using the proper compiler. There are some tricks involved in doing this. I recommend you read this article for a thorough explanation: http://around-the-corner.typepad.com/adn/2017/05/how-to-build-pillow-on-windows-with-maya-2017.html. Apart from using the adequate compiler you want setup.py to run on the proper Python interpreter (Maya’s). You might bump into additional complications in each library, which, for the most part, can be solved by reading and interpreting the error messages.
Share
Finally, if you want to save other people’s time you can then distribute this Maya friendly Python extensions building a Wheel, that can be installed using PIP. For that, I recommend reading this article: https://packaging.python.org/tutorials/distributing-packages/#id74.