0

Recently I started to use guix as my operating system.

I installed python3 for my user via guix install python3.

python itself is not available in the package repository, which I verified by running guix search python. I want to get started with org-mode and evaluate python snippets (or probably later other code-snippets as well in org-mode).

This is what I have in my init.el:

(org-babel-do-load-languages
 'org-babel-load-languages
 '(
   (emacs-lisp . t)
   (python . t)))

I evaluate the buffer to make sure the changes apply.

So here my actual question:

When I press C-c C-c above the python script, which looks like this:

#+begin_src python :results output
  print("Hello, Seaman!")
#+end_src

I get prompted to evaluate this python expression. I write "yes" and this is what comes out.

/gnu/store/295aavfhzcn1vg9731zx9zw92msgby5a-bash-5.1.16/bin/bash: line 1: python: command not found
[ Babel evaluation exited with code 127 ]

Babel is not able to find python, because I have python3 installed. Changing python to python3 in my init.el didn't help, because it displays the following after evaluating the buffer in the echo area:

Cannot open load file: No such file or directory, ob-python3. Not sure what to do here. Any help is welcome, thanks!

2 Answers 2

1

Set the Python interpreter to python3 by inserting:

  (setq org-babel-python-command "python3")

in your init.el

Emacs uses a default “python” executable, which might no be present on your system. Setting (setq org-babel-python-command "python3") points it to your installed python3 binary.

0
(use-package ob-python
  :custom (org-babel-python-command "python3"))

#+begin_src emacs-lisp :exports results :results none
(use-package ob-python
  :custom (org-babel-python-command "python3"))
#+end_src

#+begin_src python :exports results :results output
import sys
print(sys.version)
#+end_src

#+RESULTS:
: 3.11.8 (main, Mar 26 2024, 12:26:07) [GCC 13.2.0]


7
  • Thanks for the answer. I currently can't find the package in the melpa repository. Where is ob-python located. Also: Why did you assume that I use use-package? It was indeed a good guess. But I never mentioned it, which I probably should have. Commented Apr 7, 2024 at 14:20
  • Note also that I installed ob-ipython, which introduced some conflicts with org-roam, as one can see here:github.com/syl20bnr/spacemacs/issues/12375 Commented Apr 7, 2024 at 17:20
  • ob-python is part of Org mode and is installed in the same place that all the Org mode libraries are installed. use-package has nothing to do with MELPA. All that you need to ensure is that your Emacs can find the ob-python library to load it: IOW, set your load-path variable correctly (if it is not already set up correctly). Commented Apr 8, 2024 at 0:56
  • BTW, you don't have to use use-package. Customizing org-babel-python-command and setting it to "python3" in your init file should be enough. Commented Apr 8, 2024 at 1:05
  • @NickD Could you clarify how to do that? I'm not an advanced emacs user yet. So I did not install Orgmode, therefore I don't know where the Org libraries are installed. Where are those by default? How do you mean without use-package? Could you also provide the exact command? Thanks! Commented Apr 8, 2024 at 19:13

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.