How do I import nltk in python?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RSJinx
    New Member
    • Aug 2010
    • 2

    How do I import nltk in python?

    Hi. I'm totally new to Python and only have a little experience with C++. So, to begin with, I don't really know what I'm doing. I installed nltk three times - each time it said the installation was successful. But trying to import nltk only results in an error message. I tried what I found on these pages: http://groups.google.c om/group/nltk-users/browse_thread/thread/509dac376bf0630 0?fwc=1 and http://www.nltk.org/download. This is what happened:

    Code:
    Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) 
    [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    
    >>> import nltk
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named nltk
    
    >>> cd /tmp/nltk-installer
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'cd' is not defined
    
    >>> sudo python setup.py install
      File "<stdin>", line 1
        sudo python setup.py install
                  ^
    SyntaxError: invalid syntax
    
    >>> sudo easy_install -U py
      File "<stdin>", line 1
        sudo easy_install -U py
                        ^
    SyntaxError: invalid syntax
    >>>
    Any ideas? I'm sure it's something really simple. ^_^

    Thanks!
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    If you have more than one version of Python installed, you may have installed nltk to a different version of Python than the version currently active.
    Last edited by bvdet; Aug 29 '10, 03:25 PM.

    Comment

    • RSJinx
      New Member
      • Aug 2010
      • 2

      #3
      Thank you! I figured it out. Like I said, totally new to this, and I didn't realize that I needed to just be in the terminal, not python, to make those troubleshooting commands work. It all works now. : )

      Comment

      Working...