I am trying to setup company-jedi to autocomplete for python3. The autocomplete is working for standard python3 modules; however, it is not working for packages I installed using pip3, in this case numpy.
The virtualenv
package required by company-jedi has been installed using:
sudo pip3 install virtualenv
Python3 has been installed using:
brew install python3
Numpy was installed using the following command:
sudo pip3 install numpy
I have followed the instruction from this link but to no avail. If I install numpy
using pip
instead of pip3
auto-complete works; therefore, I think that jedi is still using python2 instead of python3. The command M-x jedi:install-server
does not return any errors.
The path of python3 was determined using the command which python3
.
The exec-path-from-shell
package is used to make sure the environment variables on emacs match those in the shell. Without this package the function M-x jedi:install-server
returns an error that virtualenv
does not exist.
My question is, how can I setup jedi to use python3 for auto-completion instead of python2?
Init.el
;; To get path from shell
(use-package exec-path-from-shell
:ensure t
:config
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize)))
;; Installing company mode
(use-package company
:ensure t
:config
(add-hook 'after-init-hook 'global-company-mode))
;; Disable the delay
(setq company-idle-delay 0)
(eval-after-load 'company
'(progn
(define-key company-active-map (kbd "TAB") 'company-complete-common-or-cycle)
(define-key company-active-map (kbd "<tab>") 'company-complete-common-or-cycle)
(define-key company-active-map (kbd "S-TAB") 'company-select-previous)
(define-key company-active-map (kbd "<backtab>") 'company-select-previous)))
(use-package company-jedi
:ensure t)
(defun my/python-mode-hook ()
(add-to-list 'company-backends 'company-jedi))
(add-hook 'python-mode-hook 'my/python-mode-hook)
;; Python
(setq python-shell-interpreter "python3")
(setq jedi:environment-root "jedi") ; or any other name you like
(setq jedi:environment-virtualenv
(append python-environment-virtualenv
'("--python" "/usr/local/bin/python3")))
I am currently on MacOs version: 10.13.6
jedi
wants you to have virtual environment is because it expects you to install your stuff into a virtual environment, where it will look for source to autocomplete from. To do this, first callvirtualenv -p $(which python3) .venv
, then.venv/bin/activate
, then, in Emacs,M-x pyvenv-activate .venv RET
. Install the packages you need with thepip
installed in virtual environment, includingjedi
.pyvenv
the Emacs Lisp package for working with Python mode in Emacs, orpyvenv
, the Python script that used to be distributed with Python distribution from python.org? At any rate, this is not how you are supposed to work with virtual environments. They are meant to be saved together with the project your are working on, or, they can be managed by something likevirtualenvwrapper
script. See this guide for details: python-guide-cn.readthedocs.io/en/latest/dev/virtualenvs.html .pyvenv
Emacs package. What I can't understand is how creating a new virtual environment is going to help with the autocompletion? Because the jedi plugin already creates a new virtual environment and stores it in the~/.emacs.d
directory