6

If I try this :

import nltk
text = nltk.word_tokenize("And now for something completely different")
nltk.pos_tag(text)

Output:

Traceback (most recent call last):
File "C:/Python27/pos.py", line 3, in <module>
nltk.pos_tag(text)
File "C:\Python27\lib\site-packages\nltk-2.0.4-py2.7.egg\nltk\tag\__init__.py" ipos_tag
tagger = load(_POS_TAGGER)
File "C:\Python27\lib\site-packages\nltk-2.0.4-py2.7.egg\nltk\data.py", line 605,in 
resource_val = pickle.load(_open(resource_url))
ImportError: No module named numpy.core.multiarray
Danica
  • 28,423
  • 6
  • 90
  • 122
Vinit Gaikwad
  • 329
  • 9
  • 21

2 Answers2

10

It seems that the saved word tokenizer requires numpy. You'll need to install it.

Danica
  • 28,423
  • 6
  • 90
  • 122
  • 3
    If Numpy's required by NLTK, shouldn't it be installed as a dependency automatically assuming one used Pip or other installer tools? I ask because I installed NLTK using Pip, then encountered the same issue. – Inactivist Feb 07 '13 at 15:51
  • 1
    @Inactivist Numpy's not required for most of NLTK, just some parts. (It's listed as optional on [the install page](http://nltk.org/install.html).) That said, it's super-handy to have around in general if you're doing any kind of machine learning type stuff or other number crunching. – Danica Feb 07 '13 at 16:09
  • wouldn't it be better for NLTK to split out the numpy-dependent code to a separate library – Jake Berger Jan 10 '15 at 20:04
3

Install numpy using the command:

sudo pip install -U numpy
kenorb
  • 155,785
  • 88
  • 678
  • 743