amueller / word_cloud

A little word cloud generator in Python
https://amueller.github.io/word_cloud
MIT License
10.15k stars 2.32k forks source link

Examples don't run on some platforms #576

Open GadgetSteve opened 4 years ago

GadgetSteve commented 4 years ago

Description

On Windows 10 at least some of the examples do not run giving encoding errors.

Steps/Code to Reproduce

cd examples
py parrot.py
# UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 32995: character maps to <undefined>
py emoji.py
# UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1214: character maps to <undefined>

Expected Results

Display of word cloud(s)

Actual Results

py parrot.py Traceback (most recent call last): File "parrot.py", line 23, in text = open(os.path.join(d, 'wiki_rainbow.txt')).read() File "C:\Python38_64\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 32995: character maps to

py emoji.py Traceback (most recent call last): File "emoji.py", line 27, in text = io.open(path.join(d, 'happy-emoji.txt')).read() File "C:\Python38_64\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1214: character maps to

Versions

Windows-10-10.0.18362-SP0 Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] NumPy 1.19.1 matplotlib 3.3.0 wordcoud 1.7.0

GadgetSteve commented 4 years ago

This is due to the encoding not being specified on opening the file(s) adding , encoding='utf-8') to the open calls fixes these issues.