Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Code navigation, documentation lookup and completion for Python.
Emacs Lisp Python
branch: master

Merge pull request #94 from lunaryorn/patch-1

Take virtualenv into account when checking for pip
latest commit 81c6f9e3fb
@proofit404 authored

README.rst

Anaconda mode

Build Status Coverage Status Requirements Status Melpa Melpa Stable

static/logo.png

Code navigation, documentation lookup and completion for Python.

static/goto-definitions.png

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

Installation

To use this package you need to install pip.

package.el

All you need is install the package from Melpa:

M-x package-install RET anaconda-mode RET

manual

Clone this repository somewhere and add this directory to you load-path.

prelude

anaconda-mode included into Emacs Prelude distribution. You can use it as well. Look at prelude-python module to see more details.

spacemacs

anaconda-mode included into Spacemacs distribution. You can use it as well. Look at python language contrib to see more details.

Configuration

You can automatically enable anaconda-mode in all python buffers with following code in your configuration:

(add-hook 'python-mode-hook 'anaconda-mode)

ElDoc

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)

Usage

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.

Interactive commands

Here are interactive commands available with anaconda-mode

Keybinding Description
M-. anaconda-mode-goto-definitions
M-* anaconda-nav-pop-marker
M-? anaconda-mode-view-doc
M-r anaconda-mode-usages

If goto definitions, assignments or usages cause multiple candidates you'll see advanced anaconda navigator buffer.

Tramp

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.

Implementation details

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.

PYTHONPATH

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

VIRTUALENV

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.

Bug Reports

Please attach *anaconda-mode* buffer content to every created issue.

Issues

DistutilsOptionError

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 from distutils.cfg

AttributeError and KeyError randomly happens

This kind of problems were reported with jedi 0.9 version. You can try to downgrade jedi version down to 0.8.

M-x find-library RET anaconda-mode RET
M-! rm -rf jedi* RET
M-! pip install "jedi<0.9" -t . RET

Contributions

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

Thanks

  • Dmitry Gutov @dgutov
  • Bo Lin @sadboy
  • Vasilij Schneidermann @wasamasa
  • Fredrik Bergroth @fbergroth
  • Fabio Corneti @fabiocorneti
  • Tom Davis @tdavis
  • Sviridov Alexander @sviridov
  • Mario Rodas @marsam
Something went wrong with that request. Please try again.