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 2, in <module>, "/Users/peter/Library/Application Support/McNeel/Rhinoceros/Scripts/randomfield.py"
line 2, which triggers the error is my simple import declaration
import random
When I remove that no errors until I get to the random.random() call, of course.
I’ve gone back to previous working scripts with random() call in them, and they are all broken now too.
I’ve tried reinstalling python2.7 and that hasn’t changed anything.
Does anyone have any ideas? Or even another library (rhinocommon?) where I might get access to a randomising function so I can bypass random.py altogether.
[edit] i posted this while you were editing your post and adding more info [/edit]
does this script work for you?
import rhinoscriptsyntax as rs
import random
def randomsheet():
crvlist=[]
for i in range(0,10):
ptlist= []
y=i*50
for i in range(0,10):
rand=random.uniform(0,50)
pt= ([i*50, y, rand])
pt= rs.AddPoint(pt)
ptlist.append(pt)
crv= rs.AddCurve(ptlist,3)
crvlist.append(crv)
rs.DeleteObjects(ptlist)
rs.AddLoftSrf(crvlist)
rs.HideObjects(crvlist)
randomsheet()
are you sure you’re feeding random.random the proper arguments?
random.random()
Return the next random floating point number in the range [0.0, 1.0)
This is a location that doesn’t seem to exist, so I guess it is pointing to /System/Library/Frameworks/Python… instead of /Library/Frameworks/Python…
So I’m wondering if ironpython installs its own version of python separate from the one that osx uses…
I tried copying the a newly installed version from /Library/Frameworks… to /System/Library/Frameworks… but I still get the same problem.
I wonder if I need to reinstall ironpython but I can’t remember where it came from.
I have a solution…
OK, so it’s a horrible ugle kludge but it seems to have gotten me out of trouble.
I found the hashlib.py file from the IronPython install