I followed these instructions http://www.nltk.org/install.html to install nltk module on my mac (10.6)
I have installed python 2.7, but when I open IDLE and type import nltk
it gives me this error
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import nltk
ImportError: No module named nltk
The problem is the module is installed in another python version, 2.6. How can I install the package in python version 2.7? I tried some of the solutions suggested in various answers, for example I tried typing this in the terminal
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
and then installed NLTK again with the command
sudo pip install -U nltk
but I get the message: Requirement already up-to-date in /Library/Python/2.6/. So apparently the command line export PYTHONPATH
didn't do anything (it still tries to install the package in 2.6) OR (more likely) I didn't understand the meaning/functioning of that command line. What am I doing wrong?
I would use a virtualenv, but if you really want to use it from the terminal, I'd recommend adding your export statement to ~/.bashrc
On OS X you could have multiple installation of Python, so investigate it first:
All within
/usr/bin
are built-in and all other in/usr/local/bin
are external installed by Homebrew or some other package manager.If you're using
pip
orpip3
from/usr/local
, then you've to use the same Python instance, otherwise they're different instances.Just install it via
pip
:or for Python 3:
then run the right Python instance from
/usr/local/bin
or update yourPATH
system variable.On my mac I had two different versions of Python 3 installed: Python 3.6 and Python 3.7. I had installed
nltk
having Python 3.7 in my$PATH
:But
nltk
was missing for Python 3.6. Solution: installnltk
also for version 3.6.Make sure you install the actual Python for Mac, not the one built into the console. Then, install pip by executing this script. Then skip to part 3 of the instructions and go from there.