Python environment construction (Windows10 + Emacs)

</ i> Introduction

Now that I have time, I read "Deep Learning from scratch-Theory and implementation of deep learning learned from Python". I will continue reading while moving. Since Python itself is almost the first time, I will make a note of the environment construction instead of a memorandum.

ʻEmacs 25.2` has also been released, so I'm planning to introduce it after a while.

</ i> Installing Python3

In this book, the environment is built with the Anaconda distribution, but the libraries used, [Numpy] and [Matplotlib], have recently become able to install binaries with pip (?). I installed Python from.

Download installer

Download the latest version of Python3 from the Python Software Foundation. Click "Download Python 3.6.1" to download the 32-bit installer. From "Looking for Python with a different OS? Python for Windows", select "Windows x86-64 executable installer" (python-3.6.1-". Download amd64.exe).

Installation

Start the installer. Set the installation options. Added the environment variable PATH and changed the installation destination.

Check ʻAdd Python 3.6 to PATH and click Customize installation, leave ʻOptional Features as it is, check ʻInstall fot all users, and set the installation destination to D: \ Programs \ Python36. Change to `.

The only thing I was worried about was that I didn't want to install py.exe etc. in% SYSTEMROOT% : sweat:

Module installation

Unfortunately, because we are in the Proxy environment, pip does not look outside, so we will add the Proxy setting. Also, something is displayed with pip list, so add the format with format.

Add the following contents to % HOME% / pip / pip.ini (pip / pip.ini does not exist, but newly created).

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

[list]
format = columns

I will leave the virtual environment for the time being and install it on the system. We will consider it if necessary. Launch a command prompt and install the module (> is the prompt).

> pip install numpy
> pip install matplotlib

(2017/04/24 18:10 postscript) We also need PIL, so install pillow, which is a fork of PIL.

> pip install pillow

(2017/04/24 18:10 postscript so far)

By the way, I also installed the module used by Emacs (virtalenv is for the future).

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

</ i> Emacs settings

I first tried it with python-mode.el, but when I run it with Cc Cc, I can't operate ʻEmacs. I decided to use python.el of ʻEmacs (please tell me if there is a workaround) because it became so heavy.

Add the following contents to the ʻEmacs configuration file (init.el). In my environment, ʻinit-loader is used, so the configuration files are 30-company.el and 31-python.el. Also, since ʻuse-package is used, the necessary ʻelisp will be installed automatically.

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)
  )

In my environment, this is a nice complement. Execute the buffer with C-c C-c. Since python-shell is not started when executing my-run-python with Cc Cc, it is annoying to be asked to start it first with Cc Cp. did.

Recommended Posts