Problem with python install, perhaps?


I’m working on a pretty straightforward script that requires the use of the random() function from python’s 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

  line 160, in <module>, "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/"
  line 49, in <module>, "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/"
  line 2, in <module>, "/Users/peter/Library/Application Support/McNeel/Rhinoceros/Scripts/"

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 altogether.

thanks in advance

[edit] i posted this while you were editing your post and adding more info :wink: [/edit]

does this script work for you?

import rhinoscriptsyntax as rs
import random

def randomsheet():
    for i in range(0,10):
        ptlist= []

        for i in range(0,10):
            pt= ([i*50, y, rand])
            pt= rs.AddPoint(pt)

        crv= rs.AddCurve(ptlist,3)



are you sure you’re feeding random.random the proper arguments?

    Return the next random floating point number in the range [0.0, 1.0)

Hi Jeff,

thanks for the quick response.

No luck. That script gave me exactly the same error. An error importing tracing back to

I’m assuming it works on your setup, which makes me think it must be my python installation.

ps: Nice script by the way :slight_smile:


I think there are some problems with rhino & Python that ships with 10.8…
2.7.2 I think.

Yosemite has 2.7.6.

if you open terminal and just type Python then return, what’s it say for your version?

Hi Jeff,

Thanks again.

I’m running 2.7.9 on Yosemite. Interestingly, my command line python, where random seems to work is located at


There error message points to:


And when I call ‘site.getsitepackages()’ within Rhino it points to


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.

This is a all bit beyond me, I have to say :persevere:


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 file from the IronPython install

/Users/peter/Library/Application Support/McNeel/Rhinoceros/MacPlugIns/ironpython/Lib

and copied it into the 2.7 version the rhino plugin seems to refer to, (/System/Library/Frameworks/) after renaming that one to something else.

Seems to be working for now…

I’m not sure how to reset the rhino python interpreter to look for the internal ironpython libraries in it’s default path. Any ideas?

rgds peter


I get this problem when Python 2.7.8 in installed but updating to 2.7.9 fixes it.


There’s more to it than what I said above. The discussion will continue here