Problem with python install, perhaps?

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

thanks in advance
Peter

[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():
    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)

https://docs.python.org/2/library/random.html

Hi Jeff,

thanks for the quick response.

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

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:

cheers
Peter

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

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/

There error message points to:

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py

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

/Applications/Rhinoceros.app/Contents/PlugIns/IronPython.dll/lib/python2.7/site-packages

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:

Peter

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

/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

@dromepeter,

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

Alain

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