Who knew installing Python and the NLTK module would be a massive endeavour in itself?
Apparently, MacOS comes with one version of Python (which it needs for the OS, so you shouldn’t try to uninstall it) while the current version of NLTK uses another. Also apparently, Python 2 and 3 are very different, with Python 2 being described as a “legacy” language.
What it comes down to is that if you’re running MacOS High Sierra like I am, you might need to install Python 3 separately, regardless of the fact that you “already have Python.” This installation is in tandem with the Python 2 that already lives in your Mac; your Python 3 does not replace your Python 2.
Which means, and believe me this took a while to figure out, you should use the command line:
pip3 install -U nltk
… when installing NLTK, and not, as recommended by the NLTK website:
sudo pip install -U nltk
… in which I only got an error for my troubles. (Also, I’m generally wary of using sudo, and my command line worked without it anyway.) The idea is, using “pip” will point only to your older, MacOS-bundled Python, while “pip3” specifically points the installation to your Python 3.
Once this hurdle is cleared, you now have to install the NLTK corpus. This brought up an SSL error for me when the interactive corpus downloader refused to load the available corpus catalogue. What to do?
Google it, of course. An answer on Stack Overflow recommends you type:
/Applications/Python 3.6/Install Certificates.command
… at Terminal, but my Terminal refused to acknowledge “Python 3.6” as a proper file name; it also rejected “Python_3.6” and “Python3.6.” At wit’s end, I looked up the folder itself on Spotlight, found “Install Certificates.command” in the Finder, and double-clicked it.
Reader, it worked. The interactive corpus downloader loaded properly, and I installed the corpus called “book.” I ran the test the NLTK manual recommended, and it worked like a charm:
*Don’t forget to load the damn module in Python before you proceed with the test:
>> import nltk
Otherwise, you’ll be like me and wonder why the lines you cut and paste from the NLTK site weren’t working. (Sigh.)