LoginSignup
2
2

More than 1 year has passed since last update.

elpyを使ってEmacsのpython環境を構築する

Last updated at Posted at 2022-03-07

elpy

EmacsをPythonのIDEにするようなもの.補完とか文法チェックとか色々できるようになる.

インストールと設定

melpaとかからインストールする.
下記は use-packageを使った例

;;; elpy (melpa-stable)
(use-package elpy
  :ensure t
  :pin melpa-stable
  :defer t
  :init
  (advice-add 'python-mode :before 'elpy-enable)
  :config
  (setq elpy-rpc-python-command "python3")
  (setq python-shell-interpreter "python3")
;;  (setq elpy-rpc-virtualenv-path 'current)
  (when (load "flycheck" t t)
    (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
    (add-hook 'elpy-mode-hook 'flycheck-mode)))

elpyのconfig

M-x elpy-configで設定状況が確認できる.初回実行時に色々自動で設定される.

Elpy Configuration

Emacs.............: 27.2
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python3 3.9.10 (/usr/local/bin/python3)
RPC virtualenv....: rpc-venv (/Users/xxxxxx/.emacs.d/elpy/rpc-venv)
 Python...........: python3 3.8.9 (/Users/xxxxxx/.emacs.d/elpy/rpc-venv/bin/python3)
 Jedi.............: 0.18.1
 Rope.............: 0.23.0
 Autopep8.........: 1.6.0
 Yapf.............: 0.32.0
 Black............: 22.1.0
Syntax checker....: flake8 (/usr/local/bin/flake8)

flake8はインストールされなかったので,ターミナルからpip3 install flake8でインストールした.

jedi 0.18.x で補完が効かない問題

jediのバージョンを0.18以上にするとcompanyの補完が効かなくなる問題がある
https://github.com/jorgenschaefer/elpy/issues/1890

0.17.2を使うと動くようなので,elpyのvirtualenvのpython環境でjediのバージョンを下げた.

~/.emacs.d/elpy/rpc-venv/bin/pip3 install jedi==0.17.2

このコマンドで見つからないと言われたのでPyPIからwhlをダウンロードしてきてインストールした

~/.emacs.d/elpy/rpc-venv/bin/pip3 install jedi-0.17.2-py2.py3-none-any.whl

これで補完が効くようになった

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2