Installing "Random" Module Problem

python

#1

Hello, apologies if this is a noob question.

I want to install the “random” module in my python environment. I use “sudo easy_install random” and it says it cannot find it in pypi.python.org. I looked and it looks like random is not there. My understanding is “random” is a popular module and I am confused as to why it is not on pypi. Is there another way to install it in my environment? Thank you!

Below is my Bash:

/workspace/.c9 $ sudo easy_install random
Searching for random
Reading https://pypi.python.org/simple/random/
Couldn’t find index page for ‘random’ (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
No local packages or download links found for random
error: Could not find suitable distribution for Requirement.parse(‘random’)


#2

i think it’s a built-in module, try

>>> import random
>>> random.random()
0.07880919410161458

#3

Thank you very much for taking the time to answer my question! It is really appreciated. If you still have time to help, I still get an error though when I input the import random and random.random() as you wrote in your code.

When I put in and run:
import random
random.random()

I get the Bash message:

python random.py
Traceback (most recent call last):
File “random.py”, line 1, in
import random
File “/home/ubuntu/workspace/random.py”, line 2, in
random.random()
TypeError: ‘module’ object is not callable

All attempts to Google this problem usually bring up more complicated issues. I must be missing something very basic?

Again, thank you for your time in helping to answer my questions.


#4

It seems that If you call your file random, you can’t import the global random anymore. Rename it, and make sure to delete the random.pyc file.