Not able to Import in NLTK - Python
Question: When I run this command in a file or in a shell

    
    
    import nltk
    

I get the following error :

    
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.7/dist-packages/nltk/__init__.py", line 83, in <module>
        from collocations import *
      File "/usr/lib/python2.7/dist-packages/nltk/collocations.py", line 37, in <module>
        from nltk.probability import FreqDist
      File "/usr/lib/python2.7/dist-packages/nltk/probability.py", line 45, in <module>
        import random
      File "random.py", line 2, in <module>
        T = int(raw_input())
    ValueError: invalid literal for int() with base 10: ''
    

Not able to comprehend what is going wrong.


Answer: You have a local `random` module, which masks the `random` module from
standard library.

If you try to `import nltk` from a different working directory, it should
succeed. But in general it's not a good idea name your modules after standard
modules, so please rename your `random.py` file to something else.

You for completeness, let me say that the error was obvious from the last
lines of you traceback:

    
    
      File "random.py", line 2, in <module>
        T = int(raw_input())
    ValueError: invalid literal for int() with base 10: ''
    

From the path, `random.py`, you can tell that the error is in a local file
named _random.py_. And from the exception, you know that _something_ passed an
empty string, `''`, from `raw_input` to `int` function, which failed to be
converted to `int`.

_Rule of thumb number 2_ : Always guard you executable code, in a module, in a
`if __name__ == '__main__':` block.

