Wednesday, August 28, 2019

Updating modules using Elpy

When a self written module gets updated, reevaluating the buffer and the module in the python shell inside Emacs/Elpy doesn't get updated. For solving this issue, add the following to your Emacs configuration file:

(defun my-restart-python-console ()
  "Restart python console before evaluate buffer or region to avoid various uncanny conflicts, like not reloding modules even when they are changed"
  (interactive)
  (if (get-buffer "*Python*")
      (let ((kill-buffer-query-functions nil)) (kill-buffer "*Python*")))
  (elpy-shell-send-region-or-buffer))

(global-set-key (kbd "C-c C-x C-c") 'my-restart-python-console)

restart your Emacs run your code using ```C-c C-x C-c```

In short, this code has the "if clause" for checking if *Python* buffer is open. This will help to be able to run ```C-c C-x C-c``` at any time of development even when there is no Python process already open. Another part is ```kill-buffer-query-functions``` which neglects the prompt for killing the *Python* buffer.

Wednesday, July 31, 2019

Matplotlib plot not appearing with elpy in Emacs

For solving this, you can use different back-end:

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

Other GUI backends:
  • TkAgg
  • WX
  • QTAgg
  • QT4Agg
Run your code using: C-u C-c C-c

Wednesday, July 3, 2019

Fix tmux issue with conda

source
Problem: When running a conda environment and opening tmux on macOS, a utility called path_helper is run again. Essentially, the shell is initialized twice which messes up the ${PATH} so that the wrong Python version shows up within tmux.

Solution  If using bash, edit /etc/profile and add one line. (For zsh, edit /etc/zprofile)