0
votes

Anaconda\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u2080' in position 28: character maps to

Would you please help me?

1
Can you provide some context? It looks like you are trying to print a Unicode character not supported by the current Windows code page. Use an IDE that supports UTF-8 and you'll have better luck.Mark Tolonen
from IPython.display import Image import pydot graph = pydot.Dot(graph_type='digraph', rankdir="LR") s0 = pydot.Node("S₀") s1 = pydot.Node("S₁") graph.add_edge(pydot.Edge(s0, s0, label='a₀, p=0.5, r=5')) graph.add_edge(pydot.Edge(s0, s1, label='a₀, p=0.5, r=5')) graph.add_edge(pydot.Edge(s0, s1, label='a₁, p=1, r=10')) graph.add_edge(pydot.Edge(s1, s1, label='a₂, p=1, r=-1')) Image(graph.create_png())Sa Na
Image(graph.create_png()) Anaconda\lib\site-packages\pydot.py, line 1662, in new_method format=f, prog=prog, encoding=encoding) File ...\site-packages\pydot.py", line 1836, in create self.write(tmp_name, encoding=encoding) File "C:\Users\j\Anaconda\lib\site-packages\pydot.py", line 1754, in write f.write(s)Sa Na
File ...\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u2080' in position 28: character maps to <undefined>Sa Na

1 Answers

0
votes

Yes, switch to Python 3.6+. Examples below from a Windows console:

Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'\u2080'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\dev\Python27\lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2080' in position 0: character maps to <undefined>

Python 3.3.5 (v3.3.5:62cf4e77f785, Mar  9 2014, 10:35:05) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print('\u2080')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\dev\Python33x64\lib\encodings\cp437.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2080' in position 0: character maps to <undefined>

Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print('\u2080')
₀