Python 環境.
総合環境
;;; Elpy を有効化
;; (require 'elpy)
;; (elpy-enable)
;;; 使用する Anaconda の仮想環境を設定
;; (defvar venv-default "~/anaconda3/envs/py36")
;;; virtualenv を使っているなら次のようなパス
;; (defvar venv-default "~/.virtualenvs/hoge")
;;; デフォルト環境を有効化
;; (pyvenv-activate venv-default)
;;; REPL 環境に IPython を使う
;; (elpy-use-ipython)
;;; 自動補完のバックエンドとして Rope か Jedi を選択
;; (setq elpy-rpc-backend "jedi")
python.el は公式, python-mode.el は Python コミュニティによって作成されたもの.
Emacs にデフォルトではいっているやつ.
Python コミュニティによって作成されたもの.
ショートカットがまとまっている.
(if linux-p
(setq py-install-directory "~/.emacs.d/el-get/repo/python-mode"))
(if windows-p
(setq py-install-directory "C:\cygwin64\home\tsu-nera\dotfiles\.emacs.d\el-get\repo\python-mode"))
(if windows-p
(setq python-shell-interpreter "c:/Python34/python.exe"))
(add-to-list 'load-path py-install-directory)
(require 'python-mode)
(add-hook 'python-mode-hook
'(lambda ()
(setq indent-tabs-mode nil)
(setq indent-level 4)
(setq python-indent 4)
(setq tab-width 4)
(setq imenu-create-index-function 'python-imenu-create-index)
))
Python のオムニ補完 (かしこい補完) をしてくれる.
初回利用時には、M-x jedi:install-server
他の環境で動かないので、封印
(add-hook 'python-mode-hook 'jedi:setup)
(add-hook 'python-mode-hook 'jedi:ac-setup) ;; auto-complete のソースに追加
(setq jedi:complete-on-dot t)
jump もできる.
- C-c . jedi:goto-definition
- C-c , jedi:goto-definition-pop-marker
参考リンク:
Python 用のリファクタリングツール.
うごかないよーん. python3 で動くのかな??
;; (autoload 'pymacs-apply "pymacs")
;; (autoload 'pymacs-call "pymacs")
;; (autoload 'pymacs-eval "pymacs" nil t)
;; (autoload 'pymacs-exec "pymacs" nil t)
;; (autoload 'pymacs-load "pymacs" nil t)
;; (require 'pymacs)
;; (pymacs-load "ropemacs" "rope-")
;; (setq ropemacs-enable-autoimport t)
pydoc の helm i/f.
(use-package helm-pydoc
:if linux-p
:init
(define-key python-mode-map (kbd "C-c C-d") 'helm-pydoc))
quickrun を利用すれば, python コードを Emacs から実行可能.
システムの version が 3 で, Emacs からは 2 を利用したいときは, 以下のようにすれば実行コマンドをオーバライドできる.
;; (eval-after-load 'quickrun
;; '(progn
;; (quickrun-add-command "python" '((:command . "python2"))
;; :override t)))
インタラクティブなデバッグ環境.
以下が利用できる(らしい) .
- Emacs - Flycheck を Python で使うためにしたことメモ - Qiita
- flake8
- pylint
;; (add-hook 'python-mode-hook 'my/turn-on-flycheck-mode)
flake8 をつかってみようか. #noqa をつけると、エラー対象外.
pip install flake8
flake8-python2 を利用するようにする.
-> ArchLinux から Ubuntu にしたら動かなくなっちゃった・・・ Python 書く日まで封印
;; (flycheck-define-checker python2-flake8
;; "A Python syntax and style checker using Flake8.
;; Requires Flake8 2.0 or newer. See URL
;; `https://pypi.python.org/pypi/flake8'."
;; :command ("flake8-python2"
;; "--format=default"
;; (config-file "--config" flycheck-flake8rc)
;; (option "--max-complexity" flycheck-flake8-maximum-complexity nil
;; flycheck-option-int)
;; (option "--max-line-length" flycheck-flake8-maximum-line-length nil
;; flycheck-option-int)
;; source)
;; :error-filter (lambda (errors)
;; (let ((errors (flycheck-sanitize-errors errors)))
;; (mapc #'flycheck-flake8-fix-error-level errors)
;; errors))
;; :error-patterns
;; ((warning line-start
;; (file-name) ":" line ":" (optional column ":") " "
;; (id (one-or-more (any alpha)) (one-or-more digit)) " "
;; (message (one-or-more not-newline))
;; line-end))
;; :modes python-mode)
;;
;; (add-hook 'python-mode-hook
;; (lambda () (flycheck-select-checker 'python2-flake8)))
Pygments というのをつかうらしい.
おっと、3.x は現在未サポート. 2015/07
これが使えた!
Emacs から jupyter notebook が利用できる。
ものすごくロードに時間がかかる。。。
;; (require 'ein)
;; (require 'ein-loaddefs)
;; (require 'ein-notebook)
;; (require 'ein-subpackages)
(use-package conda
: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 (see below for details), include:
(conda-env-autoactivate-mode t)
(custom-set-variables
'(conda-anaconda-home "/home/tsu-nera/anaconda3"))
(defun conda-remove-path()
(interactive)
(delq "/home/tsu-nera/anaconda3/bin" (getenv "PATH"))
)
(setq exec-path (delete "/home/tsu-nera/anaconda3/bin" exec-path))
)
- EmacsWiki: Python Programming In Emacs
- Emacs as a Python IDE - Jessica Hamrick
- Configuring Emacs as a Python IDE - Pedro Kroger
- Emacs を Python 用 IDE としてセットアップ - uchikoshi22’s blog
- emacs の python 開発環境を整える - フリーフォーム フリークアウト
- Emacs の Python 開発環境を整えた
- Vim を最強の Python 開発環境にする 2 - Λ Lisue’s blog
- gabrielelanaro/emacs-for-python