How to stop NLTK from outputting to terminal when downloading data?

A much better solution is suggested in this answer.


Old Answer:

According to the source code, nltk downloader uses straightforward print() calls to report progress. This means that there is no logger involved which you can control or pre-configure.

One of the options is to modify the sys.stdout temporarily on the fly - there is that redirect_stdout() context manager in Python 3.4+:

from contextlib import redirect_stdout
import os

import nltk
from nltk.corpus import wordnet


with redirect_stdout(open(os.devnull, "w")):
    nltk.download('wordnet')

Or some other options:

  • Suppress calls to print (python)
  • Silence the stdout of a function in Python without trashing sys.stdout and restoring each function call

Use quiet=True:

import nltk
nltk.download('wordnet', quiet=True)