emacs + elpy + pyenv-virtualenv uses system python

If I thought elpy's completions were awkward, the python environment was not from pyenv but from the system. Note that.

elpy? https://elpy.readthedocs.io/en/latest/index.html

A clever guy who does IDE-like functionality in python development.

--Complementing the members of an object and its various things --View method and class documentation --Fly to definition

And so on. To get them to do it, it seems that the jedi that I put in with pip install jedi will do it for me.

Check the current situation

Seen with M-x elpy-config

   1 Elpy Configuration
   2
   3 Virtualenv........: ml_test (/home/harumitsu.nobuta/.pyenv/versions/3.5.2/envs/ml_test)
   4 RPC Python........: 2.7.12 (/home/harumitsu.nobuta/.pyenv/shims/python)
   5 Interactive Python: python (/home/harumitsu.nobuta/.pyenv/shims/python)
   6 Emacs.............: 24.5.1
   7 Elpy..............: 1.15.1
   8 Jedi..............: Not found (0.10.2 available)
   9 Rope..............: Not found (0.10.5 available)
  10 Importmagic.......: Not found (0.1.7 available)
  11 Autopep8..........: Not found (1.3.2 available)
  12 Yapf..............: Not found (0.16.3 available)
  13 Syntax checker....: flake8 (/home/harumitsu.nobuta/.pyenv/shims/flake8)
  14

Virtualenv is 3.5.2, but for some reason RPC Python is 2.7.12. .. .. 2.7.12 is when I hit the system python command, so for some reason pyenv isn't working well and I'm referencing the system one.

Of course, the environment where jedi is put is ml_test of virtual_env, so it is not included in the system. Therefore, complementation becomes stupid.

Cause

https://github.com/jorgenschaefer/elpy/issues/803 It's stuffy because the author is stuffy.

counter-measure

https://github.com/gregnewman/emacs.d/blob/master/greg.org Write a script that sets .python-version to read well by yourself, referring to. It was surprisingly easy.

1. Create the following elisp

https://github.com/halhorn/.emacs.d/blob/master/elisp/set-pyenv-version-path.el

el:.emacs.d/elisp/set-pyenv-version-path.el


(defun set-pyenv-version-path ()
  "Automatically activates pyenv version if .python-version file exists."
  (f-traverse-upwards
   (lambda (path)
     (let ((pyenv-version-path (f-expand ".python-version" path)))
       (if (f-exists? pyenv-version-path)
           (pyenv-mode-set (s-trim (f-read-text pyenv-version-path 'utf-8))))))))
(provide 'set-pyenv-version-path)

2. Added to init.el

Or add it to .emacs. https://github.com/halhorn/.emacs.d/blob/master/init.el#L193

el:.emacs.d/init.el


(require 'set-pyenv-version-path)
(add-hook 'find-file-hook 'set-pyenv-version-path)
(add-to-list 'exec-path "~/.pyenv/shims")

Recommended Posts

emacs + elpy + pyenv-virtualenv uses system python
Install python (pyenv, pyenv-virtualenv)
python (pyenv + pyenv-virtualenv) + CentOS7 installation
Python environment construction (Windows10 + Emacs)
Presentation Support System with Python3