3

I'm new to Python/Mac OS and I'm looking to work through the NLTK textbook, but I'm having some problems installing it. I've been looking for solutions to this for a while now but unfortunately all the solutions don't seem to be able to work for me (or I'm misunderstanding exactly how to utilize them).

The basic problem I'm having is that NLTK just doesn't seem to be installed despite following the instructions. The following code gives me an error that no such module exists:

import nltk
nltk.download()

I think the problem I'm having is that pip/easy_install aren't correctly installing. From reading about a bit I suspects that this may be to do with having two versions of Python on my computer (the Mac OS X pre-installed one, and the one which I installed.) Although, at the moment I'm not sure how to check this, or which version of python the setups are utilizing. So as an initial step, how do I quickly check whether there are multiple versions of python installed on my machine?

If this turns out not to be the root cause of the problem, all of the instructions for installing pip on the following page do not work for me (all the commands return syntax errors): http://www.pip-installer.org/en/latest/installing.html.

I'm sorry for the unorganized approach to this problem, hopefully with a few pointers I'll be able to work out where I'm going wrong.

Kara
  • 6,115
  • 16
  • 50
  • 57
Isaac
  • 1,371
  • 3
  • 14
  • 36
  • 1
    This is not a programming problem. Ask the NLTK community. –  Oct 28 '13 at 18:34
  • Apart from that: the installation with Python 2.7.5 on Mavericks is working perfectly fine here. –  Oct 28 '13 at 18:36
  • There is no clear community forum, I'm really lost with this now. Very frustrating since every guide I follow runs into very complex problems that involve the terminal etc. I'm just going to have to post somewhere else and hope somebody can help. – Isaac Oct 29 '13 at 15:46
  • Welcome to SO! Have you worked with virtualenv before? Sometimes these issues come up because of unusual environments, unexpected paths coming before others, different python versions installed, etc. Virtualenv lets you create different virtual space (or _environments_) that you set up with control of what's going on inside it, so you can maybe create a clean virtualenv, try to pip install from there and see if you get the same errors. – arturomp Oct 29 '13 at 16:40
  • possible duplicate of [Python can't find module NLTK](http://stackoverflow.com/questions/27947414/python-cant-find-module-nltk) – kenorb Jul 28 '15 at 15:39
  • Where is this said NLTK community? Is there even an NLP stack? – I Heart Beats Oct 05 '15 at 01:50
  • have you resolve this issue? – raditya gumay Mar 28 '17 at 14:36
  • @radityagumay unfortunately since it was so long ago, I can't remember now – Isaac Mar 30 '17 at 12:47
  • @SamP do you using pyCharm? – raditya gumay Apr 01 '17 at 14:29

3 Answers3

3

For OS X El Captain do sudo pip install --upgrade nltk --ignore-installed six

Reimport nltk in python code afterwards

Dmitry
  • 66
  • 3
2

If you are not able to install pip try: How do I install pip on macOS or OS X?

Then try running: pip install nltk

If that fails you might need to run: sudo pip install nltk

Once that is done you should be able to import nltk

I just installed nltk on mavericks so I can confirm that it works.

Community
  • 1
  • 1
e h
  • 8,435
  • 7
  • 40
  • 58
1

I did it on Win 8 & 7 machine prior just fine, but just got a MacBookPro. You are right nothing is clear for Mac, and all you get half the time is arrogant answers from some of the people who do this for a living - not everyone can be a fulltime programmer you know. Any how I figured it out by watching this http://www.youtube.com/watch?v=c9LlK2iu7OA

  1. Download the developer kit
  2. install the dev kit
  3. open terminal
  4. Go to Home brew and scroll to the bottom of the page for the code
  5. Paste code into terminal
  6. Run Home Brew

Once you are up and running with homebrew and all the Dev kits are install the first unix/MAC NLTK instructions will work (http://nltk.org/install.html) in homebrew.. I have no idea why they don't list this on the NLTK page itself. Very counterintuitive. If you need more specifics Watch this video - it was a savior