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:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py
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
Traceback:
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.