Code navigation, documentation lookup and completion for Python.
This package support 2.6, 2.7, 3.3 and 3.4 Python versions and provide following features
- context-sensitive code completion
- jump to definitions
- find references
- view documentation
- virtual environment
- eldoc mode
To use this package you need to install pip
.
All you need is install the package from Melpa:
M-x package-install RET anaconda-mode RET
Clone this repository somewhere and add this directory to you
load-path
.
anaconda-mode
included into Emacs Prelude distribution. You
can use it as well. Look at prelude-python
module to see more
details.
anaconda-mode
included into Spacemacs distribution. You can use
it as well. Look at python
language contrib to see more details.
You can automatically enable anaconda-mode
in all python buffers
with following code in your configuration:
(add-hook 'python-mode-hook 'anaconda-mode)
anaconda-mode
provide document function to eldoc-mode
. All
you need is enable eldoc-mode
in addition to previous setup.
(add-hook 'python-mode-hook 'eldoc-mode)
To start completion press C-M-i
. This is standard emacs binding
for complete-at-point
function. You can use company-mode with
company-anaconda backend to get more intelligent ui. Or
auto-complete-mode with ac-anaconda as last try.
Here are interactive commands available with anaconda-mode
Keybinding | Description |
---|---|
C-M-i | anaconda-mode-complete |
M-. | anaconda-mode-find-definitions |
M-, | anaconda-mode-find-assignments |
M-r | anaconda-mode-find-references |
M-* | anaconda-mode-go-back |
M-? | anaconda-mode-show-doc |
If goto definitions, assignments or usages cause multiple candidates you'll see advanced anaconda navigator buffer.
Not properly implemented yet
It's possible to use anaconda-mode on remote server when you connect
to it using tramp. In case of vagrant you need to use 127.0.0.1
as tramp address.
Anaconda mode comes with anaconda_mode.py
server. This server
allow you to use jedi python library over jsonrpc api. Server choice
first available port starting from 24970. Anaconda mode will run this
server automatically on first call of any anaconda-mode command.
This mean that completion results and reference search depends on your
project installation. To make it available for anaconda-mode
you
have few options.
Add your project to Emacs PYTHONPATH
. If you store project
dependencies somewhere on you machine add its too.
M-x setenv RET PYTHONPATH RET /path/to/project:/path/to/dependency
Use virtual environment to isolate your project dependencies form other system. You can additionally install you project in editable mode into virtual environment. This will improve usage references search. Then activate this virtual environment inside Emacs.
(setq python-shell-virtualenv-path "/path/to/virtualenv")
I strongly recommended you to use pyenv-mode or similar package to
hold python-shell-virtualenv-path
in actual state.
Each action above applies to anaconda-mode
server immediately.
Next anaconda-mode
command you call will use this environment for
completion candidates search.
Please attach *anaconda-mode*
buffer content to every created
issue.
DistutilsOptionError: must supply either home or prefix/exec-prefix -- not both
This occurs due to distutils bug when pip -t
option conflict
with distutils.cfg
prefix
option. If you install pip
with
homebrew
you are on fire. There are few options to avoid this
issue.
- install
anaconda-mode
dependencies manually - remove
prefix
option fromdistutils.cfg
This kind of problems were reported with jedi 0.9 version. You can try to downgrade jedi version down to 0.8.
M-: (dired (anaconda-mode-server-directory)) RET M-! rm -rf jedi* RET M-! pip install "jedi<0.9" -t . RET
Are very welcome. But any significant change has to be accompanied with tests, both for Emacs Lisp and Python code. To run the test suite, call:
tox
- Dmitry Gutov @dgutov
- Bo Lin @sadboy
- Vasilij Schneidermann @wasamasa
- Fredrik Bergroth @fbergroth
- Fabio Corneti @fabiocorneti
- Tom Davis @tdavis
- Sviridov Alexander @sviridov
- Mario Rodas @marsam