Ask Your Question

SageTeX UnicodeDecodeError

asked 2019-04-02 13:03:58 +0200

dsejas gravatar image

Hello, Sage community. I've been writing a book with the help of SageTeX. Until yesterday, I was working with SageMath v8.6, and everything work perfectly. Today I downloaded SageMath v8.7 binary for Linux, and replaced the corresponding SageTeX files. But when I tried to compile the book, suddenly I receive an error message:

Traceback (most recent call last):

File "", line 5158, in <module>


File "/SageMath/local/lib/python2.7/site-packages/", line 276, in endofdoc


UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 29: ordinal not in range(128)

The only difference from yesterday is the new version of SageMath. Can somebody explain/help me with this matter?

Thanks in advance for your answers!

edit retag flag offensive close merge delete


What is the encoding of your LaTeX source file ? Windows' default of Latin1 is a source of endless problems.

  • Try to specify UTF-8 as your default encoding for everythng.

  • Similarly, at the top of your Sage/Python snippets, try placing # -*- coding: utf-8 -*- to clarify..


Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2019-04-02 15:56:09 +0200 )edit

I am using Linux Ubuntu. My editor (TeXstudio) is using UTF-8 encoding, and I am also using the "utf8" option for the "inputenc" package. The fist line of my "book.sagetex.sage" file is

## -*- encoding: utf-8 -*-

However, I could reduce the problem to the fact of using accented Spanish words; if I delete the accents, the problem disappears. However, with SageMath v8.6, I didn't have that problem.

By the way,the command sys.getdefaultencoding() returns 'ascii'. So I updated my locales to use UTF-8, but nothing changes.

dsejas gravatar imagedsejas ( 2019-04-02 16:19:48 +0200 )edit

However, with SageMath v8.6

Therefore it's a new problem. This bug should be reported on Trac (or, if you can't access trac, on sage-support and/or sage-release...).

Did you restart your session (or reboot) ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2019-04-02 19:29:30 +0200 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2019-04-02 22:13:16 +0200

I agree with the comments that it looks like a bug in SageTeX. I opened

In the file /SageMath/local/lib/python2.7/site-packages/, try replacing the line "m.update(bytearray(line,'utf8'))" with "m.update(line)". Does that fix it?

(In general this is probably not the right thing to do. I think it will work with Python 2 but not Python 3, but if your Sage is built with Python 2, the default, it could work.)

edit flag offensive delete link more


Thanks, this fixed the problem for me too. I had multiple lying around in my filesystem, and I needed to change it in only one of them (the others were still with the correct "m.update(line)"

ARG gravatar imageARG ( 2019-08-31 11:06:59 +0200 )edit

answered 2019-04-02 22:34:51 +0200

dsejas gravatar image


Thank you for your answers. Indeed, as indicated by John Palmieri, the error seems to happen due to the new line m.update(bytearray(line,'utf8')). If replaced with m.update(line)(i.e., the old behavior), the problem is fixed. Thank you for reporting the issue on

Coincidentally, before reading this, I could zero in on the problem, so I filed a new issue report for SageTeX ( I will mention the report by John.

Thank you very much for your help, Emmanuel and John.

edit flag offensive delete link more

answered 2019-06-18 11:06:01 +0200

Marcus gravatar image

Hello, Thank you all very much for your help! I had exactly the same problem and all seams to work fine for me now!


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-04-02 13:03:58 +0200

Seen: 613 times

Last updated: Apr 02 '19