Closed ning-y closed 3 years ago
That's correct, org-babel-python-command
won't be set in the async subprocess unless you set it in an ob-async-pre-execute-src-block-hook, like this:
(add-hook 'ob-async-pre-execute-src-block-hook
'(lambda ()
(setq org-babel-python-command "python3")))
Confirmation that this works:
#+BEGIN_SRC emacs-lisp
(setq org-babel-python-command "python3")
#+END_SRC
#+RESULTS:
: python3
Confirmation that *without* =:async=, it works as expected:
#+BEGIN_SRC python :results output
import sys; print(sys.version)
#+END_SRC
#+RESULTS:
: 3.8.2 (default, Jul 16 2020, 14:00:26)
: [GCC 9.3.0]
Confirmation that *with* =:async=, =org-babel-python-command= isn't
set:
#+BEGIN_SRC python :async :results output
import sys; print(sys.version)
#+END_SRC
#+RESULTS:
: 2.7.18rc1 (default, Apr 7 2020, 12:05:55)
: [GCC 9.3.0]
Now let's set =org-babel-python-command= in a pre-exec hook:
#+BEGIN_SRC emacs-lisp :results silent
(add-hook 'ob-async-pre-execute-src-block-hook
'(lambda ()
(setq org-babel-python-command "python3")))
#+END_SRC
And we can confirm that it now works as expected when =:async= is
enabled:
#+BEGIN_SRC python :async :results output
import sys; print(sys.version)
#+END_SRC
#+RESULTS:
: 3.8.2 (default, Jul 16 2020, 14:00:26)
: [GCC 9.3.0]
Just opened a PR that would make the pre-execute hook unnecessary. Care to try out this branch and make sure it works? https://github.com/astahlman/ob-async/pull/67
It works! Thank you very much!
Great, thanks for confirming! I'll go ahead and merge https://github.com/astahlman/ob-async/pull/67 and close this one.
Checklist
troubleshooting.org
bufferExpected Behavior
If
(setq org-babel-python-command "python3")
, thenob-async
executions should usepython3
.Actual Behavior
ob-async
executions still usepython2
.Steps to Reproduce
(setq org-babel-python-command "python3")
ob-async
usingimport sys; print(sys.version_info)
and:results output
. For example,Troubleshooting Artifacts
https://gist.githubusercontent.com/ning-y/63687521272d2489d5e3317de44017c7/raw/2adb271f8ff541f86ba3ba2abbf5d2f8a28ceb56/troubleshooting.org