I can't seem to get completion when editing an org-babel source code block.

Elpy and company-mode both appear to be enabled minor modes for the buffer, but no completion candidates appear as they do when I am editing a .py file.

Does this have something to do with visiting a "non-file" buffer? Or am I misunderstanding something about how these things should be set up?

I am running:

GNU Emacs 24.5.1 (x86_64-apple-darwin12.5.0, NS apple-appkit-1187.40)

Org-mode version 8.3.1 (release_8.3.1-196-ga395da)

Company version: 0.9.0-cvs

Elpy 1.9.0

EDIT: To clarify, I am using C-c ' to open the org-babel block up in a dedicated Org Src [ python ] buffer. Within this buffer I was not getting the kind of autocompletion I expected, but this may have been a failure to understand the way autocompletion and company works. See my answer below.

  • If you edit the code block with C-c ' does it work as expected?
    – stsquad
    Sep 3, 2015 at 18:01
  • If you miss it after pressing Tab try (setq org-src-tab-acts-natively t)
    – clemera
    Sep 3, 2015 at 21:14

1 Answer 1


The problem is ultimately the result of misunderstanding how completion works with company mode. I temporarily solved it by adding an import statement to the top of the org-babel block.

That is, typing, say sys. and awaiting the completion candidates that come with the sys module proved fruitless. However, beginning that same org-babel block with

import sys

was helpful, because now, in the next line of that same *Org Src* block, I saw:


after typing those first three characters, despite the fact that nothing had actually really been "imported." Apparently, the import statement alone was sufficient.

However, all is not well, because this kind of completion does not quite mirror that of, say, the python shell with company-mode enabled. There I simply type a module name like matplotlib and I immediately get completions, with or without an import matplotlib in that shell or not.

Since it becomes inconvenient to have to type import foo at the top of every babel block where I am interested in calling some method bar in module foo, I think a better answer would go beyond my crude solution, and may involve a deeper understanding of how company-backends or something works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.