Desperately trying to run matplotlib

76 views
Skip to first unread message

justin hidair

unread,
May 23, 2021, 10:22:29 PM5/23/21
to python_in...@googlegroups.com
Hello here fellas,
sorry for the form I'm on mobile


I've been trying everything to run matplotlib from maya (2020 win x64)

that include installing it from mayapy.exe -m pip , downloading third-party packages and other older versions ;I even tried to compile it although failing countless times at that .

And the result most of the times was you could import matplotlib at first without apparent issues but as soon as you tried to import matplotlib.pyplot you would get errors of DLL loading failure (guess it has something to do with freetype and libpng binaries which matplotlib depends on)

Now I really really want to use matplotlib from within maya. If you could help me do that and also tell me how you did it Id be super grateful and would buy you lunch via paypal or something

Alok Gandhi

unread,
May 24, 2021, 1:20:49 AM5/24/21
to python_in...@googlegroups.com
I think the only this would work is to compile it against the maya version you are using, unless there is some existing pre-built binaries that I am not aware of.

Another approach, though very convoluted, would be to first create a system level command (one that you can run outside maya from any terminal and accepts data, returns the result), call it from maya using either a Popen or os.system.  

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAHJS-05A%3DxJCD9qSj6EciaghQXvO%3DOAuJJjMkz_CEQ3KdusuqA%40mail.gmail.com.

Marcus Ottosson

unread,
May 24, 2021, 3:41:44 AM5/24/21
to python_in...@googlegroups.com

This topic is so common it really needs to be highlighted somewhere. Maybe as a new Maya splash screen? xD

notcompatible

The problem though is that many packages are compatible, it’s only the compiled packages that are not. So it’s understandable that it keeps getting confused. Can only imagine the number of hours lost trying to shoehorn PyPI into Maya, and the subsequent number of hours struggling with random crashes due to suceeding to shoehorn it in; when it seems to work - like NumPy sometime does - but really shouldn’t.

I even tried to compile it although failing countless times at that .

The trick is compiling it with Maya’s Python, it’s the only way. In most cases it really needs to be mayapy, since it itself was built with a different compiler than the one on python.org. The same compiler as Maya was built with, and the same compiler your library needs to be built with. Which is why you most often also need a separate build for each major version of Maya, see the development docs for which compiler version they use and when they switch. Some versions of Maya use the same.

I was looking for an example of how PyQt is compiled for Maya that isn’t too convoluted. The process would be similar here. The closest one I can find that contains each step is this.

Replacing any mention of python with mayapy and (optionally, but safest) explicitly passing Maya’s Python headers to configure.py or setup.py etc.

Maybe someone else has a guide on compiling anything for Maya specifically? It can be really hard, like NumPy, because of all the dependencies involved. But sometimes the light shines on you and it’ll be over before you know it.


justin hidair

unread,
May 24, 2021, 7:15:47 AM5/24/21
to Python Programming for Autodesk Maya
re, yes forgot to mention my attempts at compiling it were made with mayapy.exe, still failed with opaque error messages

I don't think there's a silver bullet, each library build has its quirks and challenges despite the community trying to adhere to standards
there are like massive disparities on how easy it is to build something versus how confusing and annoying it is to build another 

Marcus Ottosson

unread,
May 24, 2021, 7:59:52 AM5/24/21
to python_in...@googlegroups.com

Could you post some of those error messages? Maybe someone here recognises and could help resolve those.

I don’t think there’s a silver bullet, each library build has its quirks and challenges despite the community trying to adhere to standards there are like massive disparities on how easy it is to build something versus how confusing and annoying it is to build another

I think we’ve got C and C++ to thank for this haha. Or rather, thank Python for shielding us from the horrors of compiled software out there, it’s hard to understate how much more accessible it makes programming for this benefit alone. I bet anyone dabbling with C++ can attest to the pain and recurrence of dependencies in everyday life. For a modern example, just look at USD!

That said, it’s certainly possible. One clue might be looking at how the native Python packages are built for matplotlib.

The curveball Maya throws at you is that most build scripts out there assume a system-wide install of Python, and makes hardcoded assumptions about where to find libraries and headers. In a CI environment like that, it wouldn’t be unreasonable to mount Maya’s files over the native ones, to trick such build scripts into using the proper ones.


justin hidair

unread,
May 24, 2021, 1:41:45 PM5/24/21
to Python Programming for Autodesk Maya

Marcus Ottosson

unread,
May 24, 2021, 2:00:04 PM5/24/21
to python_in...@googlegroups.com

Here we go, lots of clues.

c:\users\pf02\appdata\local\temp\pip-req-build-jo5j0f>call “C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd” /Release /x64 /xp
The system cannot find the path specified.

Problem number 1, you’ll need Visual Studio. Not only that, you need the version of Visual Studio Maya was built with. For example, for Maya 2020, that version is Visual Studio 2017.

c:\users\pf02\appdata\local\temp\pip-req-build-jo5j0f>call “C:\Users\PF02\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat” x64
Setting environment for using Microsoft Visual Studio 2008 x64 tools.

Problem number 2, this is another one of the the hardcoded assumptions I mentioned above, whereby you didn’t actually tell it to use Visual Studio 2008 and yet that’s what it’s trying to use. That’s what Python coming off of python.org used, so it’s assumed true here. You can’t rely on that.

The remaining issues in that log is because of these two primary ones.

So why is this happening?

mayapy -m pip install

Because of this. This calls on pip to pull out whatever rabbits out of whatever hats are necessary to build something on whatever platform you are on. In most cases, it does a good job. Because pip is related to PyPI which is related to python.org. So the hard-coded assumtions are often true.

The main thing you need to rectify is that version of Visual Studio it’s trying to use. I set this up recently but more-or-less copy pasted whatever I found online about it.

These two lines presumably overrides this particular assumption. I got that from here:

With that, it’ll use whichever cl.exe is on your PATH rather than look for it. Which means you need to call vcvarsall64.bat ahead of time.


Justin Israel

unread,
May 24, 2021, 2:00:17 PM5/24/21
to python_in...@googlegroups.com


On Tue, 25 May 2021, 5:41 am justin hidair, <justin...@gmail.com> wrote:
here's the best I managed https://gist.github.com/yetigit/c2f55bdb8b1798b2936687567f9c6c1e


Looks like maybe the wrong Visual Studio C++ compiler for Maya 2020? In addition to C++being difficult to build, combining that with Maya on Windows is even harder. 
I don't have much experience compiling on windows so maybe a windows user will recognize the fix. 
A quick look shows that Maya 2020 says it uses Visual Studio C++ 2017. 

justin hidair

unread,
May 24, 2021, 3:07:15 PM5/24/21
to Python Programming for Autodesk Maya
thank you guys going to try all the suggestions 
but wouldn't it make sense to have the same MSVC version as the one they built their  python with ? 

cmd_uw6R7GsUGh.png

this is visual studio 2015 here not 2017, so ??? 
but yeah let's go on with the rest of the suggestions first 

justin hidair

unread,
May 24, 2021, 4:51:56 PM5/24/21
to Python Programming for Autodesk Maya
Re, unfortunately those env variables are not discarding vs2008 
tried as admin, tried to restart , tried powershell as well 
it's as if nothing happened at all, quite frustrating honestly 

>  I don't have much experience compiling on windows so maybe a windows user will recognize the fix. 

man you're blessed not to have to deal with such bullsh*t

AK Eric

unread,
Sep 18, 2021, 2:32:28 PM9/18/21
to Python Programming for Autodesk Maya
FWIW, I've always had trouble using pip to install python packages in Python 2.7.  I'm now on 2022 / Python 3.7 now, and installing packages via pip amazingly, 'just works'.  I can install matplotlib, numpy, scipy, pandas, tensorflow, etc, all just via pip.

Run shell as admin and:
> "C:\Program Files\Autodesk\Maya2022\bin\mayapy.exe" -m pip install matplotlib --target "C:\some\optional\custom\path\if\you\want\site-packages"

Autodesk themselves have updated their docs with this info:

Now, this won't help you if you're still on Python 2.7 : Just calling out that there 'is hope', somewhere in the future, once you move to Python 3.

vince touache

unread,
Sep 18, 2021, 8:16:29 PM9/18/21
to Python Programming for Autodesk Maya
awesome, thank you so much for the tip AK Eric!! I didn't know, that is such a gamechanger! cheers
Reply all
Reply to author
Forward
0 new messages