2
1

More than 3 years have passed since last update.

【Emacs】Pythonの自動補完パッケージjediのインストールで困った話(mac)

Last updated at Posted at 2020-08-09

はじめに

・環境
macOS Mojave 10.14.6
GNU Emacs 26.3

macでemacs-jediを導入しようとしたところ、ハマりました。
もともとjediを使用していたのですが、python自体の環境が変わったのに伴い再インストールを試みました。
そういえば最初にインストールした時も、大変だった記憶があります。

ちなみに、もともとの設定はこちら。


(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:complete-on-dot t)

macとjediは相性が悪いのか、例えばこんな情報もあります。
https://github.com/tkf/emacs-jedi/issues/346

また、デフォルトではvirtualenvのpythonを見に行くというのもややこしい...。

その時の状況

jedi自体のインストールはM-x package-list-packageから問題なくできたのですが、M-x jedi:install-serverでエラーが発生しました。

 deferred error : (error "Deferred process exited abnormally:
  command: virtualenv
  exit status: exit 1
  event: exited abnormally with code 1
  buffer contents: \"FileExistsError: [Errno 17] File exists: '/usr/local/opt/python@3.8/bin/pytho\
n3.8' -> '/Users/username/.emacs.d/.python-environments/default/bin/python'
\"")

ドキュメントhttp://tkf.github.io/emacs-jedi/latest/#jedi:install-server

環境は〜/ .emacs.d / .python-environments / default /にあります

とあるので、ここに古いpython環境が残っているのが原因かと思い、これを削除


rm -r .emacs.d/.python-environments/default

して再びM-x jedi:install-serverを実行しましたが、以下のエラーが出て残念。

Traceback (most recent call last):
  File "/Users/username/.emacs.d/.python-environments/default/bin/jediepcserver", line 5, in <module\
>
    from jediepcserver import main
ModuleNotFoundError: No module named 'jediepcserver'

Process epc:server:3 exited abnormally with code 1

解決編

こちらの記事に救われました...!
http://proglab.blog.fc2.com/blog-entry-46.html

この記事を要約すると

結局、jedi, epc, jediepcserver がインストールされていれば virtualenv で仮想環境を構築してやらなくても良いのでは…、ということに気がつきました。


 pip install --upgrade ~/.emacs.d/elpa/jedi-core-なんちゃら

を実行して設定ファイル(ex. ~/.emacs)に


(setq jedi:server-command (list (executable-find "jediepcserver")))

を追記すれば良い。

とのことで、実際に自分の手元でもこれで解決しました!

最後に

jediは便利なので、これが再び使えるようになったのは本当にありがたいです。
以上のエラーに対する有効な対策をご存知の方がいたら、教えていただきたいです。

2
1
0

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
1