python-nltk on Ubuntu 12.04 LTS: nltk.download('brown') results in HTML error 401
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?
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', ...]
>>>
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.