Kerstin Kerstin -4 years ago 177
Python Question

Import of nltk with python 2.7.13 and windows fails

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:


  • cycler 0.10.0

  • functools32 3.2.3.post2

  • matplotlib 2.0.2

  • nltk 3.2.3

  • numpy 1.12.1

  • pyparsing 2.2.0

  • python-dateutil 2.6.0

  • pytz 2017.2

  • PyYAML 3.12

  • six 1.10.0



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!

Answer Source

First of all, to fix your problem, the easiest way is to install the requests package.

pip install requests

But I wrote an answer not just because of that, but also I'm here to recommend you install nltk from pypi with pip install not from the exe file they say to do. Note: pip also works splendidly on Windows. There is several advantage to using pip:

  1. The package is always up-to-date, since the exe is usually always out-of-date

  2. Pip will automatically install all the necessary dependencies

  3. It's easy and fast

All you need to do is:

pip install nltk 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download