when I run a script from Windows with import random and use random functions, it failed. any ideas?
Hi can you give more details of what you are doing and what error messages you get?
Are you running in the Rhino Script editor with _EditPythonScript ?
The following works for me on Rhino 5 for pc:
import random
print random.randint(1,42)
xkcd has a workaround if you need it
1 Like
Alain
(Alain Cormier)
February 6, 2019, 4:04pm
4
I can run the script above in Rhino 5 for mac.
Yes more details would be useful
thank you for your reply!
I run the same script in Mac rhino 5, it failed.
I cannot open edit python script, but I can use atom.
if I delete “import random”, it works.
Ahh I don’t know about that. Have you done anything with your python installation outside of Rhino? Anything in your site packages folder that could be interferring with random, with the sys or os module or with hashlib ?
Any changes to your atom setup, e.g. the character encoding?
Thank you very much! as you mentioned the hashlib, I found these articles as others met. I copy the module from rhino 6 in windows to Mac. It works!
Hi,
I’m working on a pretty straightforward script that requires the use of the random() function from python’s random.py library. When I try to run the script, I get the following execution error:
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"
line…
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…
Alain
(Alain Cormier)
February 7, 2019, 3:45pm
8
@herocaripod , what version of Rhino are you running?
rhino for Mac 5.0.1 (5A858)
Alain
(Alain Cormier)
February 8, 2019, 12:30am
10
That explains it. The problem you’re experiencing was fixed in 5.1.
Thank you! I will upgrade it.