cannot import name urandom

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
fellows
Posts: 0
Joined: Fri May 10, 2013 11:53 pm

cannot import name urandom

Post by fellows »

from within Blender (2.49b), when I try to run a Python script containing the line: "from os import urandom"

I get the error: "ImportError: cannot import name urandom"

My setup:
Ubuntu 12.04 LTS, 64-bit version
Blender 2.49b (blender-2.49b-linux-glibc236-py26-x86_64)
Python2.6.8

from within stand-alone python the same command ("from os import urandom") works fine, but not from within Blender's python.

I've searched around for hours and have not found a solution.

By the way, I am running the older Blender version because I am trying to use it with MBDyn and this requires the older Blender.

Any suggestions would be greatly appreciated.

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

are there two different python installations maybe? One with that module, and another without?
I'm sitting, waiting, wishing, building Blender in superstition...

fellows
Posts: 0
Joined: Fri May 10, 2013 11:53 pm

Post by fellows »

CoDEmanX wrote:are there two different python installations maybe? One with that module, and another without?
Thanks for the quick reply.

There are several versions of python on my machine, yes, and they all have the os module since it is a built-in.

I don't think that's the problem, though, because Blender is able to find the correct Python ("Compiled with PYthon version 2.6.2. Checking for installed Python... got it!"). Also, "import os" from within Blender works.

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

if "import os" works, can't you do

Code: Select all

import os
os.urandom(#)
?
I'm sitting, waiting, wishing, building Blender in superstition...

fellows
Posts: 0
Joined: Fri May 10, 2013 11:53 pm

Post by fellows »

CoDEmanX wrote:if "import os" works, can't you do

Code: Select all

import os
os.urandom(#)
?
Nope, that doesn't work either. I get "AttributeError: 'module' object has no attribute 'urandom'

Incidentally, if I run the following in Blender
import os
import inspect
print inspect.getfile(os)

I get /usr/lib/python2.6/os.pyc

which is also what I get when running the same code from Python in a terminal (outside Blender). So it looks like they are calling the same os.pyc code, yet in one case it can find urandom and in the other it can't. Strange.

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

that's really weird, maybe ask over at python.org?
I'm sitting, waiting, wishing, building Blender in superstition...

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

It appears to be an OS-related problem, here's a possible fix:

https://gist.github.com/PureForm/5340738

Maybe this helps to test if urandom exists:

Code: Select all

os_module = __import__("os")
print(hasattr(os_module, "urandom"))
I'm sitting, waiting, wishing, building Blender in superstition...

Post Reply