Maya 2016 and compiled modules

Hi.
I’ve bumped into a problem with Perforce python module in Maya 2016.
Maya 2016 is compiled using Visual Studio 2012 and default Python 2.7 is compiled with VS 2010 so none of pre-built binaries are working.
Anyone got succesfull with compiling any python extensions with Maya2016? I’ve came to the point where the code compiles but it fails to link properly :frowning:

Ok - here’s a solution for all the people who will face the same problem in the future.

I assume you have a VS2012 already installed in your system, you also need a standard python2.7 64bit installed in your system.
Now - download p4python sources and p4api, first is a source of the module, the other one is a C++ API for perforce. I’ve managed to make a successful build with p4api_vs2012_dyn, maybe someone will succeed with p4api_vs2012_static (APIs can be downloaded from: http://www.perforce.com/product/components/apis

Download zipped source and C++ api and launch the command line in which you type:


set VS90COMNTOOLS=%VS110COMNTOOLS%

After that you follow the build instructions from p4python and type:


c:\Python27_64\python.exe setup.py build --apidir PLACE_WHERE_YOUR_PERFORCE_C++_API_IS

Your P4.py and P4API.pyd should appear in a build/lib.win-amd64-2.7 folder and it imports/works fine in Maya2016.
Sounds very easy but if you have also VS2010 installed on the same system you’ll have to do some more serious hacking:

To force distutils to use precisely this version of Visual studio compilers that you want you have to open file: c:\Python27\Lib\distutils\msvc9compiler.py

There you navigate to line 226. here you can see:


    try:
        productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
                                   "productdir")
    except KeyError:
        productdir = None

This tries to find Visual studio compilers in the registry.
To prevent that just add another line:


    try:
        productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
                                   "productdir")
    except KeyError:
        productdir = None
    [B]productdir = None[/B]

this:
productdir = None
is crucial because it occludes the registry value and forces distutils to look into VS90COMNTOOLS to find the compilers (and this is pointing to the VS2012 folder).

This worked for me, hope that it will work for you too for other modules as well.

So I’ve already compiled p4python for Maya 2015/16 (They both use Python2.7 and VS2012)
While it isn’t hard to recompile it yourself, in case you want to be a bit lazy, you can get it here

you can also give this a shot https://pypi.python.org/pypi/python-perforce/0.1.0

/shamelssplug