scimax
scimax copied to clipboard
How to use Python 3 by default?
Maybe what you can do is to create a pyenv for python 3. You can do it using the command pyvenv-create inside emacs.
That does not work. I use a venv with python 3.6 and the only jupyter kernel for that ve is python3. But the ipython code blocks use python 2.7. (I am using Ubuntu and emacs 26)
This would by my approaches, in order of preference.
- Install python3 so it is the system default.
- Customize
ob-ipython-command
to launch a python3 version of ipython - Customize
org-babel-python-command
to launch the python3 of your choice - this doesnt' make it default, but you can use :python /path/to/python3 on a per python block basis I think, and probably set it as a generic header in the file..
The only missing piece was the ob-ipython-command
. Now it is working fine. Thank you!
An unrelated topic: I noticed a JSON error in the upstream version of ob-ipython see here caused by an unexpected error message in the shell. Maybe it will come up here, so it may be good to be aware of.
... and as I predicted, the JSON error occurred. The problem is that any warning that happens in the shell command produces a JSON readtable error in the .org file. It happens when using #+INCLUDE:
, for instance.
Setting ob-ipython-command
to ipython3
does not help because it causes some warnings in the shell (with python 3.6.1), which results in JSON readtable error.
The solution I found was to let ob-ipython-comman
to jupyter
to use the jupyter console, but modify this function below to include the argument "--kernel=python3"
. It is a provisory solution, but make it possible to use ob-ipython (upstream version) in combination with your enhancements.
(defun ob-ipython--kernel-repl-cmd (name)
(list ob-ipython-command "console" "--simple-prompt" "--existing" "--kernel=python3"
(ob-ipython--kernel-file name)))
Can you give me mwe org file that causes the json warning? I never see this issue my self.
I saw your issue on ob-ipython. I am not sure what the best solution here is. It sounds like you have some shell interaction causing the problem. I don't see that here. I will be out for the next week, when I get back I will see if it seems to be a windows/linux issue.
Here is a mwe:
#+TITLE: title
#+INCLUDE: tmp2.org
* A section
#+BEGIN_SRC ipython :session tmp :exports both :results output
print("ok")
#+END_SRC
I am using
I have good experiences on scimax using anaconda python (rather than the system's python) and pyvenv
on both Ubuntu and Fedora. I put this code in my user.el
near the top:
;; pyvenv setup
(require 'pyvenv)
(setenv "WORKON_HOME" "~/anaconda/envs/")
(setq pyvenv-workon "python36")