I have a problem with PythonTeX and Beamer : I don't understand why the code below doesn't work: \stdoutpythontex is supposed to print the last output of the last block of python instructions, but it doesn't here.

Moreover, when you call \stderrpythontex, the line number is false, even with the option fragile=singleslide.

Could you please help me with this?




\frametitle{Affichage à l'écran: Commande \pyv{print()} }  
\item En mode console:   résultats automatiquement affichés.
\item Dans l'éditeur: utiliser \pyv{print()}

a, b =  2, 3
print(a, 'hello', a+b)
a pour résultat

De plus, 
a = 5
print('a vaut ' a)

  • A tip: You can use backticks ` to mark your inline code as I did in my edit.
    – jub0bs
    Commented Aug 7, 2014 at 8:18
  • ok, sorry I'll do it from now
    – guillaume
    Commented Aug 7, 2014 at 8:27

1 Answer 1


In your current configuration, everything is executed in a single Python session. The second chunk of code triggers a syntax error, which is caught before any code is executed. The syntax error prevents any code from running, so the first chunk never gets to print.

The line numbering shown in the error (4) is correct, because the syntax error was in the 4th line of your code (again, everything is in a single session). This didn't line up with the line numbering shown in the slide, though, because you weren't using firstnumber=last.

If you want both examples to work, independently, then you should put them in separate sessions. Maybe use \begin{pyblock}[stdout][numbers=left] for the first one, and \begin{pyblock}[stderr][numbers=left] for the second one.

  • OK, thanks for these explanations (though I spent many hours on your exhaustive documentation, I realize I didn't understand the idea of many sessions, which is actually great!) By the way, thanks again for you PythonTex package!
    – guillaume
    Commented Aug 7, 2014 at 14:56
  • @guillaume Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you.
    – jub0bs
    Commented Aug 7, 2014 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .