Kerstin
Kerstin

Reputation: 3

Import of nltk version 3.2.3 fails with ImportError

I'm running python 2.7.13 under windows 10 and I'm struggling to get nltk properly running.
Here's what happens when I try to import nltk:

>>> import nltk
Traceback (most recent call last):
File "<pyshell#4>", line 2, in <module>
 import nltk
File "C:\Python27\lib\site-packages\nltk-3.2.3-py2.7-win32.egg\nltk\__init__.py", line 128, in <module>
 from nltk.chunk import *
File "C:\Python27\lib\site-packages\nltk-3.2.3-py2.7-win32.egg\nltk\chunk\__init__.py", line 157, in <module>
 from nltk.chunk.api import ChunkParserI
File "C:\Python27\lib\site-packages\nltk-3.2.3-py2.7-win32.egg\nltk\chunk\api.py", line 13, in <module>
 from nltk.parse import ParserI
File "C:\Python27\lib\site-packages\nltk-3.2.3-py2.7-win32.egg\nltk\parse\__init__.py", line 81, in <module>
 from nltk.parse.corenlp import CoreNLPParser, CoreNLPDependencyParser
File "C:\Python27\lib\site-packages\nltk-3.2.3-py2.7-win32.egg\nltk\parse\corenlp.py", line 17, in <module>
 import requests
ImportError: No module named requests

The following packages are installed:

I have already tried to uninstall nltk and also uninstalled and reinstalled python and then I followed these instructions: http://lizusefulstuff.blogspot.de/2012/03/how-to-install-nltk-package-for-python.html

However, with these instructions I get stuck with step 5. When I enter

python -m nltk.downloader

I get the message

C:\Python27\python.exe: No module named requests

Does anyone have a hint what I'm doing wrong here or what else I could try to get nltk running in my setup? I assume there is still a way to use nltk with python 2.7?

From what I found so far, it seems easier to install nltk with python 3.4 but I'd like to avoid a python upgrade, if possible, since aside from my nltk experiments I'm following along a coding tutorial that refers to python 2.7.

Thank you for any hints!

Upvotes: 0

Views: 1463

Answers (1)

alvas
alvas

Reputation: 122280

In the latest version of nltk (v3.2.3), there's an issue with "optional" dependency, see https://github.com/nltk/nltk/issues/1725

The ImportError would happen in any OS (Windows / Linux / Mac) since it's a python dependency issue.

This is due to the additional dependency that nltk.parse.corenlp needs but it isn't elegantly imported and the imports were exposed at the top level at https://github.com/nltk/nltk/blob/develop/nltk/parse/init.py#L81

To install nltk with requests to patch this problem:

pip install -U nltk[corenlp]

For fuzz-free installation, installs all packages that all nltk submodules would require:

pip install -U nltk[all]

Alternatively, you can install the request package separatedly:

pip install requests

Hopefully, issue #1725 gets resolved soon and a minor patched version of the release will be re-released soon.

Upvotes: 1

Related Questions