1

I'm very new to org-mode and org-babel. After installing oh-my-zsh I noticed that I cannot run the source code in my org files like before.

My code is like follows

#+BEGIN_SRC python :results output  :session

# some computations

#+END_SRC

I noticed something went wrong because after I ran the source block code, the output showed the prompt you get when you call python through the terminal, given below.

#+RESULTS: 
#+begin_example
WARNING: Python 2.7 is not recommended. 
This version is included in macOS for compatibility with legacy software. 
Future versions of macOS will not include Python 2.7. 
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Feb 29 2020, 01:55:37) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
'org_babel_python_eoe'
16286.2414
#+end_example

(I also got some other problem which got fixed after adding (setq python-shell-completion-native-enable nil) to the init.el file if that helps)

When everything was working just fine, I just got

#+RESULTS: 
16286.2414

Which is what I want.

I then added the following to my init.el file

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

After which it is loading an installation of Python 3 BUT it doesn't have the packages I previously made use of in the same file (numpy, scipy etc) when everything was working fine

Any ideas on how to fix this? I also noticed when I run the code block for the first time, the Python and Clang version come up like when you open the Python REPL on the terminal, this did not happen before as well. Which Python installation does org-babel even load?

Uninstall oh-my-zsh didnt work

3 Answers 3

0

It sounds like there might be a few things going on here, but the first thing that comes to mind is if your Emacs knows what path to find your executables here, namely python3? It may not be added to your PATH explicitly. Are you using a package like https://github.com/purcell/exec-path-from-shell or setting this manually in your Emacs config?

Two other things that could be conflating this issue is:

  • The Python code that's being executed in the source block
  • oh-my-zsh's PATH or the PATH of bash, if that's what you're falling back to now (?)
0

So the problem was specific to GUI emacs, the PATH variable was not the same as what I have in my .zshrc (the PATH is correct when you open emacs via the shell, the PATH can be checked by M-x getenv)

So I used this neat package which loads the correct PATH even I open the GUI emacs now.

0

If preferred, you can set you PATH correctly without an additional package using:

  ;; Use the PYTHONPATH defined in whatever shell config: zshrc or bashrc or wherever
  (setenv "PYTHONPATH" (shell-command-to-string "$SHELL --login -c 'echo -n $PYTHONPATH'"))

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.