As in the title, If I have an org file with a python source block of the form

#+BEGIN_SRC python :results none :session py-sess :exports none 
import numpy as np
import matplotlib.pyplot as plt

and doing C-c C-e l o produces a .pdf file with the code block exported, despite the :exports none header.

Adding :eval never-export does not help solve this.

The only way I can get around this is if I have a section heading with :noexport as the tag, but this is not what I want to do in my document structure, as I want to have an org file with python code blocks producing plots which I export to the .pdf.

As well as this, exporting this block via LaTeX to .pdf

#+BEGIN_SRC python :results file :session py-sess :exports results


produces both the figure and the code block.

How can I stop the code blocks from being exported? Is there some hidden setting I'm missing in org-babel?

EDIT Found the problem -- had another package (ob-sagemath) which had the line (setq org-export-babel-evaluate nil) in its use-package config. It seems that that variable should be set as t. I guess I could have found it sooner, but at the same time having that variable be t is a little counter-intuitive in preventing code from being exported.

Also, it took a while to figure this out as there was some weird issue in that a Python source block which printed out help(plt.savefig) caused the export process to crash (the python shell/session just got stuck), but only when running emacs in daemon/client mode and worked fine in "standalone mode". Removed that block and everything worked fine.

  • 1
    FWIW, I cannot reproduce this with Org mode version 9.5.1 (release_9.5.1-279-g8908fb) - what version of Org mode are you using?
    – NickD
    Dec 25, 2021 at 21:48
  • 1
    If there is no obvious error, i would edebug org-babel-exp-do-export and see what it returns and, if not the empty string, why it returns a a non-empty string result.
    – NickD
    Dec 25, 2021 at 22:17
  • I'm using Org mode version 9.4.4 (release_9.4.4 @ /usr/share/emacs/27.2/lisp/org/) Dec 26, 2021 at 16:03
  • You should also try with emacs -q, if only to eliminate the possibility that your init file is doing things it shouldn't be doing.
    – NickD
    Dec 26, 2021 at 18:51
  • I cannot reproduce this with Org mode version 9.4.4 either.
    – NickD
    Dec 26, 2021 at 18:55


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.