import random error

Russell Blau russblau at
Thu Aug 5 23:37:12 CEST 2004

"Rob B" <mrbrown200425 at> wrote in message
news:7903bb89.0408051324.63ee1535 at
> I am just starting to learn Python and was writing a simple script on
> my machine (Mac OS X 10.3.4), but I can't seem to import the random
> module:
> #!/usr/bin/env python
> import random
> Results in:
> Traceback (most recent call last):
>   File "./", line 3, in ?
>     import random
>   File "/sw/lib/python2.3/", line 42, in ?
>     from math import log as _log, exp as _exp, pi as _pi, e as _e
> ImportError: cannot import name log
> I have such a feeling that this is either a) because I don't know what
> I'm doing or b) the python install is somehow strange. What is strange
> is that in interactive mode, import random works fine.

Neither (a) nor (b).  It is c) you have named your program "" but
"math" happens also to be the name of a module in the standard Python
library, and the "random" module needs access to the "math" module.  But
when it searches the Python path for a module named "math" it comes upon
your file first.

Simple solution:  call your program something else!  (and make sure you
delete from your working directory).

I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.

More information about the Python-list mailing list