9

I have installed python-nltk on Ubuntu Server 12.04 using apt-get.

But when I try to download a corpus, I get the following error:

$ python
Python 2.7.3 (default, Feb 27 2014, 19:58:35)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> nltk.download('brown')
[nltk_data] Error loading brown: HTTP Error 401: Authorization
[nltk_data]     Required
False

Am I missing some configuration or additional package?

  • You could try installing from source wget https://github.com/nltk/nltk/archive/develop.zip; unzip develop.zip; cd nltk-develop; python setup.py install. But an issue has been raised in github.com/nltk/nltk/issues/747 – alvas Sep 23 '14 at 10:14
  • This is still a problem with Ubuntu 13.04 – Tickon Sep 27 '14 at 11:34
  • Revisiting this question after a long time and some system upgrades: The issue is no longer there with ubuntu 18.04 LTS – jk - Reinstate Monica Sep 26 '18 at 17:40
12

The DEFAULT_URL used in downloader.py of the Ubuntu packaged version still uses:

DEFAULT_URL = 'http://nltk.googlecode.com/svn/trunk/nltk_data/index.xml'

But the current data server is:

DEFAULT_URL = "http://nltk.github.com/nltk_data/"

You can of course install from source or... modify your already installed version to point to the new server like this:

 sudo perl -pi -e 's#DEFAULT_URL = .*#DEFAULT_URL = "http://nltk.github.com/nltk_data/"#' /usr/lib/python2.7/dist-packages/nltk/downloader.py

You can then install the "brown" corpus:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> nltk.download('brown')
[nltk_data] Downloading package 'brown' to /home/sylvain/nltk_data...
[nltk_data]   Unzipping corpora/brown.zip.
True
>>> from nltk.corpus import brown
>>> brown.words()
['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', ...]
>>> 
12

It is possible to fix this without changing the source code. Create a custom downloader in python:

>>> dl = nltk.downloader.Downloader("http://nltk.github.com/nltk_data/")

then you open a GUI dialog:

>>> dl.download()

Check you have write access to the download directory and download what you need.

0
pip install nltk --upgrade

This one updates the nltk and then nltk.download() works again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.