Closed hongyi-zhao closed 3 years ago
comint-mime only makes sense in comint buffers, and you added it to python-mode-hook
:-)
you added it to
python-mode-hook
Thank you for pointing this out. I've removed the corresponding setting.
Then how to reproduce the example shown here? I tried by both M-x eshell
and M-x term
, and then run the corresponding python codes with ipython
and python
, but none of them shown the plot in Emacs' frame:
You need the good old Python shell, M-x run-python
. And by the way, the package needs Emacs 28. Both Emacs 28 and this package are unreleased as of yet.
Still failed to do the trick by the following steps:
M-x run-python RET
M-x comint-mime-setup RET
Then input the python codes as following:
Are you using Emacs 28, with a freshly compiled master branch?
Yes. I use the self compiled git master version: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2021-09-09
.
Does the other example of the screenshot (with LaTeX output) work? I've found the Matplotlib part of the setup to be finicky. Sometimes typing %matplotlib inline
in the shell helps. Otherwise, let me know if you figure this out, because I'm not sure either.
Thank you again for your comment. According to the suggestion and documentation described here and here, I created the following ipython
configuration file:
$ cat ~/.ipython/profile_default/ipython_config.py
c.InteractiveShellApp.matplotlib = 'inline'
Then I restart Emacs with pyvenv
installed, hit C-c C-p
followed by C-c C-c
, and the example you give is reproduced:
import matplotlib.pyplot as plt
from numpy import arange, pi, sin
from sympy import Symbol, integrate
t = arange(0, 2 * pi, .01)
plt.plot(sin(4 * t), sin(5 * t))
x = Symbol('x')
integrate(1/(1+x ** 3))
The complete configuration of the above test is as follows, and see here for relevant discussion:
(use-package comint-mime
:straight (:host github :type git :repo "astoff/comint-mime"
:files (:defaults "*.py" "*.sh"))
:hook ((shell-mode inferior-python-mode) . comint-mime-setup)
:custom
(org-format-latex-options '(plist-put org-format-latex-options :scale 1.5))
(use-package pyvenv
:init
(setenv "WORKON_HOME" "~/.pyenv/versions")
;https://lists.gnu.org/archive/html/help-gnu-emacs/2021-09/msg00535.html
(defun try/pyvenv-workon ()
(when (buffer-file-name)
(let* ((python-version ".python-version")
(project-dir (locate-dominating-file (buffer-file-name) python-version)))
(when project-dir
(pyvenv-workon
(with-temp-buffer
(insert-file-contents (expand-file-name python-version project-dir))
(car (split-string (buffer-string)))))))))
:config
(pyvenv-mode 1)
(setq pyvenv-post-activate-hooks
(list (lambda ()
(when (executable-find "ipython3")
(setq python-shell-interpreter "ipython3"
;;python-shell-interpreter-args "-i --automagic --simple-prompt --pprint"
;; Or use the following args, without the corresponding setting in `~/.ipython/profile_default/ipython_config.py`
python-shell-interpreter-args "-i --matplotlib=inline --automagic --simple-prompt --pprint")))))
(setq pyvenv-post-deactivate-hooks
(list (lambda ()
(setq python-shell-interpreter "python3"))))
)
I tried with the following example:
The corresponding Emacs configuration:
When I run the python code, I meet the following error:
Any hints for this problem?
Regards, HZ