nltk.corpus.reader.NKJPCorpusReader fails on Python 3.x
Author: bieniekCreated Sep 24, 2019Updated Sep 10, 2026
NKJPCorpusReader object inside is using tempfile library which is different in v. 2.7 and 3.5. In Python v.2.7:
self.write_file = tempfile.NamedTemporaryFile(delete=False)creates file with mode='w'
In python v3.x
creates file with mode='w+b' which makes line 274 of '~/.pyenv/versions/3.7.4/lib/python3.7/site-packages/nltk/corpus/reader/nkjp.py' failing with error:
TypeError: a bytes-like object is required, not 'str'
Addition of explicit mode is required to fix it.
Source: nltk/nltk