Skip to content

Instantly share code, notes, and snippets.

@vishalbelsare
Created September 22, 2019 13:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishalbelsare/a3ed6c8d2df1bc50469f8e4f36e0a50a to your computer and use it in GitHub Desktop.
Save vishalbelsare/a3ed6c8d2df1bc50469f8e4f36e0a50a to your computer and use it in GitHub Desktop.
Elpy and conda for a complete python config with Anaconda Python Distribution (handles virtualenvs including python process)
;; See my explanation of this config here: https://github.com/jorgenschaefer/elpy/issues/1087
(provide 'my-python-config)
(require 'python)
;;; NOTE: PATH environment var must have your path to Anaconda
;;; environment, e.g., ~/anaconda/bin, as the last thing for
;;; everything else below to work.
;;; [[file:~/Encrypted/org-mode-repo/OrgModeFiles/howto-python.org]]
;;; explains how to work with Anaconda virtual envs and Emacs.
;;; Removed my elpy and ob-ipython config as the first I don't use,
;;; because I use other packages, and the later because it doesn't
;;; work properly with my config
;;; [[id:A7A9B251-33B2-4FE7-99C1-BF42760E9678][file:~/elisp/config/my-python-config.el]]
;;; TODO Still need to learn how to use with pycscope.
;;; Disabled until then. I am hopeful that pycscope, cscope will give better
;;; jump to definition than elpy, jedi, anaconda-mode, and maybe even better
;;; than PyCharm.
(use-package helm-cscope
:disabled t
:ensure t)
;;; NOTE conda is needed to set anaconda virtual environment python process.
;;; Elpy can set the anaconda virtual env, but not the process. conda uses
;;; environment.yml (I think to find the process).
(use-package conda
:ensure t
:init
(setq conda-anaconda-home (expand-file-name "~/anaconda"))
:config
;; If you want interactive shell support, include:
(conda-env-initialize-interactive-shells)
;; If you want eshell support, include:
(conda-env-initialize-eshell)
;; If you want auto-activation, include:
(conda-env-autoactivate-mode t)
;; Activate the project/virtual env you want to use.
;; Via M-x conda-env-activate RET analyticd-pysystemtrade
;; or
;; (conda-env-activate "analyticd-pysystemtrade")
)
;;; NOTE I have everything I need with conda, anaconda-mode, and
;;; python-mode. I don't need elpy.
(add-to-list 'package-archives
'("elpy" . "https://jorgenschaefer.github.io/packages/"))
;; NOTE elpy provides pyvenv and many other systems for python
;; hacking like jedi, etc. I prefer elpy to anaconda-mode or to just
;; jedi mode.
(use-package elpy
;; :disabled t
:ensure t
:config
(require 'ag)
(after 'my-ag-config
(defun my-python-jump-to-definition (string directory)
"Search using ag in a given DIRECTORY for a given literal search STRING,
with STRING defaulting to the symbol under point."
(interactive (list (ag/read-from-minibuffer "Search string")
(read-directory-name
"Directory: "
(concat python-shell-virtualenv-root
"/"
"/lib/python3.6/site-packages/"))))
(ag/search string directory)))
(defun goto-def-or-rgrep ()
"Go to definition of thing at point or do an rgrep in
project if that fails"
(interactive)
(condition-case nil (elpy-goto-definition)
(error (elpy-rgrep-symbol (thing-at-point 'symbol)))))
(bind-key "M-." 'goto-def-or-rgrep elpy-mode-map)
(bind-key "M-C-." 'my-python-jump-to-definition elpy-mode-map)
(elpy-enable))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment