This gives you a modern editing experience with:
- Autocomplete and error checking (Elpy + Flycheck)
- Proper Git integration (Magit)
- A great package manager within Emacs (MELPA)
- Install Python:
sudo apt update && sudo apt upgrade sudo apt install python3-dev python3-pip python3-venv
- Install Emacs:
sudo apt install emacs
Note: If you prefer your editors terminal-based use the
emacs-nox
package. - Set up MELPA:
Add the following:emacs ~/.emacs
(require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) ;; Comment/uncomment this line to enable MELPA Stable if desired. See `package-archive-priorities` ;; and `package-pinned-packages`. Most users will not need or want to do this. ;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t) (package-initialize)
- Close and open Emacs.
- Refresh the package list:
M-x package-refresh-contents
- Show the package list (
M-x package-list-packages
) and install the following packages:- elpy
- flycheck
- magit
- poetry
- Configure Emacs:
Add the following:emacs ~/.emacs
;; Python IDE (defvar myPackages '(elpy flycheck ) ) (elpy-enable) (when (require 'flycheck nil t) (setq elpy-modules (delq 'elpy-module-flymake elpy-modules)) (setq elpy-eldoc-show-current-function nil) (add-hook 'elpy-mode-hook 'flycheck-mode) (add-hook 'elpy-mode-hook 'poetry-tracking-mode)) ;; Magit (global-set-key (kbd "C-x g") 'magit-status)
- Open a
.py
file. - Set up the Elpy virtual environment:
You will be asked "Automatically install the RPC dependencies from PyPI", answer yM-x elpy-rpc-reinstall-virtualenv
- Always put the correct shebang at the top of Python scripts:
#!/usr/bin/env python3
- Make your scripts exectuable:
chmod +x example.py
- Run scripts from inside Emacs with:
M-x compile
./example.py
The nice thing about this is you can jump straight to errors with:
CTRL-x + `
- Open Magit with:
CTRL-x + g