Issue while importing nltk package in Python
Question: When I type

    
    
    import nltk
    

in the Python interpreter, it gives me this --

    
    
    >>> import nltk
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 105, in <module>
        from collocations import *
      File "/usr/local/lib/python2.7/dist-packages/nltk/collocations.py", line 38, in <module>
        from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
      File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/__init__.py", line 16, in <module>
        from nltk.metrics.scores import          (accuracy, precision, recall, f_measure,
      File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/scores.py", line 16, in <module>
        from scipy.stats.stats import betai
      File "/usr/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 7, in <module>
        from stats import *
      File "/usr/lib/python2.7/dist-packages/scipy/stats/stats.py", line 198, in <module>
        import distributions
      File "/usr/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 87, in <module>
        from new import instancemethod
      File "new.py", line 3
    
            ^
    IndentationError: expected an indented block
    

I took a look at new.py which I found in /usr/lib/python2.7/ and found
everything ok.

    
    
    """Create new objects of various types. 
     Deprecated.This module is no longer required except for backward compatibility.
     Objects of most types can now be created by calling the type object.
    """
    from warnings import warnpy3k
    warnpy3k("The 'new' module has been removed in Python 3.0; use the 'types' "
                "module instead.", stacklevel=2)
    del warnpy3k
    
    from types import ClassType as classobj
    from types import FunctionType as function
    from types import InstanceType as instance
    from types import MethodType as instancemethod
    from types import ModuleType as module
    
    from types import CodeType as code
    

Any solutions?


Answer: You have a _local_ file named `new.py`. Check your current directory and
rename it or delete it.

You can see this in the traceback:

    
    
      File "/usr/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 87, in <module>
        from new import instancemethod
      File "new.py", line 3
    

The preceding module has a full filepath, but the `new.py` file does not,
making it a local file that is shadowing the relative import in
`scipy.stats.distributions`.

