I'm trying to do pretty much the same thing as in here Typeset functions with PythonTeX and execute them in console afterwards, except that I'd like to use some unicode characters (French accents: é, è, etc.). However, the answer provided there fails to work in that case (during the pythontex run).
See the following MWE (where if I change Résultat in Resultat, it works fine):
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pythontex}
\newenvironment{pyconcodeblock}%
{\VerbatimEnvironment
\begin{VerbatimOut}{temp.py}}%
{\end{VerbatimOut}%
\pyconc{exec(compile(open('temp.py', 'rb').read(), 'temp.py', 'exec'))}%
\inputpygments{python}{temp.py}}
\begin{document}
\begin{pyconcodeblock}
def foo(x):
print("Résultat :", 2*x)
\end{pyconcodeblock}
\begin{pyconsole}
x = 10
foo(x)
\end{pyconsole}
\end{document}
(I'm using PDFLaTeX and Python 3 provided by WinPython.)
Would you have any ideas to make this works?
PS: the entire message I get when running pythontex is:
This is PythonTeX 0.15
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "C:\python\WinPython-64bit-3.4.3.2\python-3.4.3.amd64\lib\multiprocessing
\pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "c:\texlive\2016\texmf-dist\scripts\pythontex\pythontex3.py", line 2273,
in do_pygments
content = f.read()
File "C:\python\WinPython-64bit-3.4.3.2\python-3.4.3.amd64\lib\codecs.py", lin
e 319, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 24: invalid
continuation byte
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\texlive\2016\texmf-dist\scripts\pythontex\pythontex.py", line 62, in
<module>
pythontex.main()
File "c:\texlive\2016\texmf-dist\scripts\pythontex\pythontex3.py", line 2676,
in main
do_multiprocessing(data, temp_data, old_data, engine_dict)
File "c:\texlive\2016\texmf-dist\scripts\pythontex\pythontex3.py", line 1369,
in do_multiprocessing
result = task.get()
File "C:\python\WinPython-64bit-3.4.3.2\python-3.4.3.amd64\lib\multiprocessing
\pool.py", line 599, in get
raise self._value
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 24: invalid
continuation byte
C:\texlive\2016\bin\win32\runscript.tlu:679: command failed with exit code 1:
python.exe c:\texlive\2016\texmf-dist\scripts\pythontex\pythontex.py test.tex
pycodeenvironment the stringu"Résultat :"(note the prefixu) is printed correctly, so I seeRésultat : 20in the PDF. – Fran Sep 11 '16 at 19:12