numpy errors fixed when reintializing maya

45 views
Skip to first unread message

Rudi Hammad

unread,
Apr 30, 2021, 10:57:55 AMApr 30
to Python Programming for Autodesk Maya

Hello,

has anyone experienced this type of behavior working with numpy? I know my code is correct because I unitest method and all tests pass. But from time to time, complety randomly, when i run the unitest I get 17 errors all related to methods that use numpy.
When this happened the first time, I spent hours thinking what was happening, since I didn't modify anything and no matter how much i looked into it everything looked totally okey.
Then I used the best debuging tool, which is turn off and on again maya, and it was fixed.

Since then, I don't waste my time anymore when i get this strange errors because i know it is not something wrong in my code. And reinitializing maya fix the issue.
So I wonder if anyone has a similar experience.

Could it be something related with a presicion that need to be set somewhere when using numpy? I always set a tolerance aroung 0.001, so I am not taking a risk comparing very small values.

cheers

Alok Gandhi

unread,
Apr 30, 2021, 11:34:22 AMApr 30
to python_in...@googlegroups.com
And what are the errors? Any logs?


--
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/b7388dc6-daf1-4dd7-b7d3-d3c9a234080bn%40googlegroups.com.

Rudi Hammad

unread,
Apr 30, 2021, 1:20:10 PMApr 30
to Python Programming for Autodesk Maya
I'll let you know when the error happens again, since I don't know how to cause it. I think it is something related to can't do what ever with None, or something referencing a built-in numpy method.
I know this doesn't help so when  it happens again, I'll post it.

Marcus Ottosson

unread,
Apr 30, 2021, 2:34:23 PMApr 30
to python_in...@googlegroups.com

Did you happen to get NumPy from PyPI, via pip install? There was a thread here about it not long ago, but the bottom line is if you haven’t got a version compiled specifically for your version of Maya, it won’t behave.


Alok Gandhi

unread,
Apr 30, 2021, 3:30:19 PMApr 30
to python_in...@googlegroups.com
And as this is not reliably reproducible, and a restart seems to fix it for a while, I would not rule out any memory issues. Keep an eye on the memory next time it happens. 

Rudi Hammad

unread,
Apr 30, 2021, 6:44:02 PMApr 30
to Python Programming for Autodesk Maya
Hey Marcus,
no, I didn't pip install, since maya 2018  needed to be specific compiled numpy (and scipy) compatible with it. I can't remember where I found it, I remember it took me a while to get the right one. I can use it with no problem,
it is just a rare issue that happens sometimes. I will be moving soon to maya 2021 with python 3.7 that includes the oficial numpy so...it alright, I just wondered if it sound familiar to anyone.

Rudi Hammad

unread,
Apr 30, 2021, 6:51:34 PMApr 30
to Python Programming for Autodesk Maya
sure, I will.
I had a similar issue once at work. Not with numpy but with a unitest when comparing matrices using MMatrix.isEquivalent(). In my computer all the tests passed, so I pushed my code into the servered. But strangly enough,
in my colleague computer the same code didn't passed. So we reduce the tolerance argument, and then it passed. Almost like my cpu could handle to compare the float percision but his couldn't.
So maybe it is maya messing thing is up depending on how the cpu is feeling that day? I don't know....

Marcus Ottosson

unread,
May 1, 2021, 2:40:49 AMMay 1
to python_in...@googlegroups.com
> I can use it with no problem, it is just a rare issue that happens sometimes.

Ah, ok. The reason I ask is because this sounds like the kind of problems you would get with a version compiled for a different Python. Random, subtle, memory related. I would double-check where you got it from, and make sure it was actually compiled for your version of Maya.


Juan Moraga

unread,
May 1, 2021, 4:22:04 AMMay 1
to python_in...@googlegroups.com
I agree on what Marcus said, pip install Numpy is not reliable (from what I have experienced in the past anyway), at least for Maya 2018.7 (and I can imagine with MayaPy2.7 in general).

Kind regards!

Rudi Hammad

unread,
May 2, 2021, 5:38:04 PMMay 2
to Python Programming for Autodesk Maya
I got the log error. Here it is:

# ======================================================================
# ERROR: test_average (domain._unittest.testmath.test_numeric.TestNumeric)
# ----------------------------------------------------------------------
# # Traceback (most recent call last):
#   File "D:\domain\_unittest\testmath\test_numeric.py", line 8, in test_average
#     assert np.allclose(numeric.average(((0,-2), (1, 2))), [0.5, 0.0] , atol=0.01)
#   File "D:\domain\math\numeric.py", line 33, in average
#     averageList.append(np.average(_))
#   File "C:\Program Files\Autodesk\Maya2018\Python\lib\site-packages\numpy\lib\function_base.py", line 514, in average
#     avg = a.mean(axis)
#   File "C:\Program Files\Autodesk\Maya2018\Python\lib\site-packages\numpy\core\_methods.py", line 54, in _mean
#     arr = asanyarray(a)
TypeError: 'NoneType' object is not callable


Remember that this error was fixed on its own just by restarting maya. Any idea what could be happening?

Justin Israel

unread,
May 2, 2021, 5:45:59 PMMay 2
to python_in...@googlegroups.com
Shot in the dark.... are you using python's reload() functionality anywhere? Does it seem to break after some type of workflow operation?

Rudi Hammad

unread,
May 2, 2021, 5:59:36 PMMay 2
to Python Programming for Autodesk Maya
no, I don't used reload(). To avoid using reload everywhere I use this.
https://pastebin.com/sxhYQNTn

Justin Israel

unread,
May 2, 2021, 6:16:28 PMMay 2
to python_in...@googlegroups.com
On Mon, May 3, 2021 at 9:59 AM Rudi Hammad <rudih...@gmail.com> wrote:
no, I don't used reload(). To avoid using reload everywhere I use this.
https://pastebin.com/sxhYQNTn

Hmm, but you are still trying to dynamically change the imported module objects to force a re-import. Might not be related at all, but these workflows don't play very nicely with compiled extensions (numpy) which can't really be unloaded entirely from memory.
 

Rudi Hammad

unread,
May 2, 2021, 7:01:13 PMMay 2
to Python Programming for Autodesk Maya
okey. well, I'll just have to deal with it. Maybe thing's will get better with python 3 in maya 2021

Alok Gandhi

unread,
May 3, 2021, 1:36:51 AMMay 3
to python_in...@googlegroups.com
Seems like a known bug in numpy related to re-initialization of core module.




Rudi Hammad

unread,
May 3, 2021, 8:05:06 AMMay 3
to Python Programming for Autodesk Maya
awesome, thanks for pointing that out.

Rudi Hammad

unread,
May 5, 2021, 9:51:21 PMMay 5
to Python Programming for Autodesk Maya
By the way,  I modified the script i linked above in paste bin to not include any module related to numpy  and it fixed the bug since it doesn't reimport those modules.
thanks again for the tips.
Reply all
Reply to author
Forward
0 new messages