Exception from hashlib.py, OS X 10.10.5, Python 2.7.10. (was: Which Python Standard Library should Rhino's IronPython use?)

Rhino Python is actually an IronPython interpreter running in the Common Language Runtime of the .NET framework. (On Mac it’s inside Mono.) When I run Python scripts in Rhino, it appears that imports from the Python Standard Library are coming from the externally installed Python instead of from the library installed with Rhino’s IronPython. For instance, I run the following script:

import random

(That’s it. That one line is all that’s in the file. That’s enough to throw an exception.) I get an exception that traces back through:


Even though this exists:

~/Library/Application Support/McNeel/Rhinoceros/MacPlugIns/ironpython/Lib/random.py

I suspect this is because the external version of the library is in the Python path, and Rhino’s IronPython version is not. To see the path the interpreter is using to find modules on import, run this in Rhino Python:

import sys
print sys.path

Maybe the exception is happening because the non-IronPython version of random.py has code that’s incompatible with the IronPython interpreter.

There is an old post with what looks like the same problem here. The only proposed solution in that thread is to copy the IronPython random.py to the external install of Python, which seems to me like a Very Bad Idea.

Which copy of the Standard Library should Rhino Python be using? And if it’s correct to use the external version, then why is the IronPython version installed?

Please correct me if I’ve gotten any of the details wrong above.

I’m running Rhino for Mac version 5.0.2 (5A865) on Yosemite 10.10.5 (Build 14F27).

EDIT 2015-08-28 to clarify:

Here’s more of the error message:

Exception Occurred
Message: sequence item 0: expected bytes or byte array, str found
  line 160, in <module>, "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py"
  line 49, in <module>, "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py"

For latecomers to the thread: The .py files in ~/Library/Application Support/McNeel/Rhinoceros/MacPlugIns/ironpython/Lib/ are a red herring, left over from an early experimental install of Rhino Python years ago. See @stevebaer’s first reply below.

I don’t believe we have shipped the standard lib with the python plug-in for a long time. Did you install an old copy of the python plug-in separate from Mac Rhino at some point in the past?

Hi @stevebaer ,

I am currently experiencing this problem as well on my Macbook Pro.

import random

throws an error:

sequence item 0: expected bytes or byte array, str found


Thanks, @stevebaer, that answers the question posed! Rhino’s IronPython interpreter should be using the externally-installed Python Standard Library as it is, and in fact the only reason I have the other copy of the library is because it’s a leftover from when I first installed Rhino Python a long time ago, when it was installed differently than it is now.

Unfortunately, that still leaves the question of why I’m getting this exception. At least now I know I’m not the only one, thanks @Helvetosaur. But that’s outside the topic indicated by the title of the thread. Should I start a new one?

Yeah, I have Mac Rhino installed on this computer since WIP1, and Python since it has been available. Scripts I have written with just rhinoscriptsyntax and rhinocommon have always run on this computer though and still do. However importing random seems to trip it, and this is the first time I’ve seen this happen.

How does one uninstall the old Python so this will work again?


All of the python “stuff” is in your
~/Library/Application Support/McNeel/Rhinoceros/MacPlugIns/IronPython
~/Library/Application Support/McNeel/Rhinoceros/Plug-ins/IronPython

If you close Rhino and delete these two directories, you should get a fresh version of python the next time you start Rhino.

OK, trying that now… Hmm, don’t have the second directory. Deleting the first one didn’t help… :frowning:

Is there anything in the
~/Library/Application Support/McNeel/Rhinoceros/Plug-ins

Directory doesn’t exist on this machine…

@alain, can you try and repeat this bug?

It looks like you don’t have any remnants of the old python plug-in installed.

OK, something else wrong then… :confused:

I’m not having that problem. Let me look into it …


I get the error with python 2.7.8 but not with 2.7.9.

Let me know if updating Python to 2.7.9 fixes your problem.


How do I know which version I have? All it says is 2.7… Somewhere I thought I even saw a reference to 2.7.10… Do Apple system updates install the latest Python version?


Hey Mitch,


python --version

at the command line.

OK, I had previously typed python -v and got a whole bunch of info…

Typing --version gets me 2.7.10… So the latest is installed (the system just auto-updated to 10.10.5 day before yesterday). Maybe that’s the problem?

Thanks, --Mitch

Yep. It doesn’t work in 2.7.10 for me as well )-:

From 2.7.8 to 2.7.9 a block of code that was removed from hashlib.py that was causing the problem but it was added back to 2.7.10.

OK, I guess that’s going to cause problems for a lot of people then as various systems update to 10.10.5… apparently out since 13 August, but since I was on vacation at that time…

Is this something that can be patched from the McNeel end of things? Even if so, I guess that would only mean it would be fixed for 5.1 and the WIP.


There’s more to this story.

I thought it was strange that a block had been removed just to be re-added in 2.7.10 so I downloaded the source code for 2.7.9 and the block of code is there (in hashlib.py) !

I have an idea what might be going on … investigating some more …