Sometimes your Python and the Python Blender was built for is not exactly compatible. For instance, when I do a simple “import random” in 2.42a from Blender Foundation, I get:
Traceback (most recent call last):
File "Text", line 5, in ?
File "/usr/lib/python2.4/random.py", line 44, in ?
from math import log as _log, exp as _exp, pi as _pi, e as _e
ImportError: /usr/lib/python2.4/lib-dynload/math.so: cannot open shared object file: No such file or directory
although both Python versions (Blender and mine) are 2.4, and /usr/lib/python2.4/lib-dynload/math.so is present. When I do the same in my self compiled Blender 2.42a, all is well.
If I try your code, it works in both Blender versions for me, though. This is on Ubuntu 6.06 LTS (Dapper) with Python 2.4.3.