LoginSignup
12
12

More than 5 years have passed since last update.

Python の環境構築(Windows10 + Emacs)

Last updated at Posted at 2017-04-24

はじめに

時間ができたので,流し読みした『ゼロから作るDeep Learning ――Pythonで学ぶディープラーニングの理論と実装』を手を動かしながら読み進めることにします.Python 自体もほぼ初めてなので環境構築を備忘録代わりにメモします.

Emacs 25.2 もリリースされたので,しばらく様子を見て導入しようと思っています.

Python3 のインストール

この本には,Anaconda ディストリビューションで環境構築するようになっていますが,使用するライブラリ,【Numpy】,【Matplotlib】も最近ではpip でバイナリをインストールできるようになった(?)ので素の Python をインストールしてみました.

インストーラーのダウンロード

Python Software Foundation から Python3 の最新版をダウンロードする.
『Download Python 3.6.1』をクリックすると 32bit のインストーラがダウンロードされるので,「Looking for Python with a different OS? Python for Windows」から,「Windows x86-64 executable installer」(python-3.6.1-amd64.exe)をダウンロードする.

インストール

インストーラーを起動して.インストールオプション を設定する.環境変数の PATH の追加とインストール先を変更しました.

Add Python 3.6 to PATH にチェックを入れて,Customize installation をクリック,Optional Features は取り敢えずそのままで,Install fot all users にチェックを入れ,インストール先を D:\Programs\Python36 に変更する.

ただ一つ気になるのは,%SYSTEMROOT%py.exe などをインストールしないで欲しかったです:sweat:

モジュールのインストール

残念ながら,Proxy 環境下にいるため,pip がお外を見てくれないので,Proxy の設定を追加します.また,pip list でなんか表示されるので,format で書式を追加します.

%HOME%/pip/pip.ini に下記の内容で追加します(pip/pip.ini は無いの新しく作りました).

[global]
proxy = [user:passwd@]proxy.server:port

[list]
format = columns

仮想環境とか取り敢えず置いておいてシステムにインストールすることにします.必要になれば検討します.コマンドプロンプトを立ち上げて,モジュールをインストールします(> はプロンプト).

> pip install numpy
> pip install matplotlib

(2017/04/24 18:10 追記)
PIL も必要になったので,PIL の fork である pillow をインストールする.

> pip install pillow

(2017/04/24 18:10 追記ここまで)

ついでに,Emacs で使用するモジュールもインストールしてます(virtalenv は今後のため).

> pip install jedi
> pip install epc
> pip install flake8
> pip install virtualenv

Emacs の設定

最初に python-mode.el で試していたのですが,C-c C-c で実行すると,Emacs が操作できないぐらい重くなったので,Emacspython.el を使うことにしました(対処方法があれば教えてください).

Emacs の設定ファイル(init.el)に下記内容を追加します.私の環境では,init-loader を使っているので,設定ファイルは,30-company.el31-python.el にしています.また,use-package を使用しているので,必要な elisp を自動でインストールしてくれます.

init.el
(use-package company
  :ensure t
  :config
  (add-hook 'after-init-hook 'global-company-mode)
  (setq company-tooltip-align-annotations t
        company-tooltip-flip-when-above t
        ;; Easy navigation to candidates with M-<n>
        company-show-numbers t)
  :diminish company-mode)

(use-package company-quickhelp
  :ensure t
  :after company
  :config
  (company-quickhelp-mode t))

(use-package company-jedi
  :ensure t
  :after company
  :config
  (setq jedi:complete-on-dot t)
  (defun config/enable-company-jedi ()
    (add-to-list 'company-backends 'company-jedi))
  (add-hook 'python-mode-hook 'config/enable-company-jedi))

(use-package python
  :mode ("\\.py\\'" . python-mode)
  :interpreter ("python" . python-mode)
  :config
  ;; https://github.com/jorgenschaefer/elpy/issues/887
  (setq python-shell-completion-native-enable nil)
  ;; https://emacs.stackexchange.com/questions/16361/how-to-automatically-run-inferior-process-when-loading-major-mode
  (defun my-run-python ()
    (save-selected-window
      (switch-to-buffer-other-window (process-buffer (python-shell-get-or-create-process (python-shell-parse-command))))))
  (add-hook 'python-mode-hook 'my-run-python)
  )

私の環境では,これでよしなに補完してくれます.C-c C-c でバッファを実行します.my-run-python は,C-c C-c で実行するときに python-shell が起動していないので,C-c C-p で先に起動してねと言われるのが煩わしくて設定しました.

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12