OrenSL
OrenSL

Reputation: 21

Installing NLTK for Python 3.3 using Terminal on a Mac

I am studying how to use Python for Natural Language Processing. The NLTK module is required. I installed Python and NLTK and everything worked just fine. When I tried to upgrade Python, the NLTK installation disappeared. I am now using Python 2.7.5 on Terminal (on a Mac), and it is not possible to install NLTK. I followed the instructions on the NLTK website, but nothing works, the error I get is that there is no such module as NLTK. I downloaded Python 3.3 and tried to install NLTK through Eclipse, but again, nothing works. How can I install NLTK on either Python 3.3 using eclipse OR install NLTK through the Terminal using Python 2.7.5? How can I sort the mess of having too many Python versions? Thanks!

Upvotes: 1

Views: 2163

Answers (1)

abarnert
abarnert

Reputation: 365915

Let's answer these in reverse order:

How can I sort the mess of having too many Python versions?

Get rid of the extras!

Having Python 2.x and 3.x in parallel is fine. Having Python 2.x and 2.y or 3.x and 3.y in parallel is fine, as long as you remember to always use the specific versions of everything (e.g., run python2.7 instead of python, or pip-3.3 instead of pip3). Having Python 2.x.y and 2.x.z in parallel (or two different 2.x.y) is a big problem. Unless you really need to do it for some reason, don't put yourself through the headache. Just stick with Apple's 2.7.5 (Mavericks) or 2.7.2 (Snow Leopard through Mountain Lion). See this blog post for more details.

So, how do you get rid of your extra Python 2.7.5? That depends entirely on how you installed it. If you used a package manager like brew or port, it will have an uninstall command; if you used an installer package, it may or may not have come with an uninstaller; in some cases, you may have to manually track down and delete everything. Since you haven't said how you installed 2.7.5, I can't give any specific instructions. But if you search this site or Google with the appropriate information, like "uninstall ActiveState Python Mac", you'll find them pretty quickly on your own.

How can I install NLTK … through the Terminal using Python 2.7.5?

Most likely the top pip on your PATH is the one that goes with Apple's Python 2.7, but the top python on your PATH is the one that goes with your other 2.7. And this is exactly the kind of problem you get by having two Python 2.7 versions. If you want to learn about how to figure out what's where and how PATH finds things, how Python/easy_install/pip decides where to put things that it installs, where your multiple site-packages are, how pig-resources works, etc., then go learn all of that and you will be able to make this work. Otherwise, don't try it.

How can I install NLTK on … Python 3.3.

You can't. As the homepage says, "NLTK requires Python versions 2.6-2.7." 3.3 is not 2.6-2.7.

There is a port to Python 3, but it's (a) a separate project, (b) still in alpha, and (c) not yet installable via pip.


In summary:

Keep your Python 3.3; it's not hurting anything. But don't try to use NLTK with it.

Get rid of your extra Python 2.7; it's the cause of all of your problems.

Once you've cleaned up the extra Python 2.7, install NLTK by following the instructions.

Upvotes: 4

Related Questions