Adam Oudad

Adam Oudad

(Machine) Learning log.

2 minutes read

Emacs has this very powerful package Elpy which is usually recommended if you want to code in Python.

Docker can containerize your Python interpreter so that you can seemlessly run your applications on any device.

In Emacs with elpy installed, C-c C-c binding (C is for Control key) runs elpy-shell-send-region-to-buffer and is very handy for running on the fly python commands for testing your code. It actually use the content of the variable python-shell-interpreter for the python interpreter.

The default value of this variable is "python", which will most likely run your system-wide python interpreter. What we want is to run the following command which will send our python code to a running container.

docker run -it -v /tmp:/tmp -v $(pwd):/code ufoym/deepo python3

See docker command line reference for details about this command. However just setting python-shell-interpreter to this will raise an error.

Python shell interpreter 'docker run -it -v /tmp:/tmp -v $(pwd):/code ufoym/deepo python3' cannot be found. Please set the value 'python-shell-interpreter' to a valid binary.

Emacs needs a shell script, so for example, you can set

(setq python-shell-interpreter "~/.docker-python-shell.sh")

Then the file ~/.docker-python-shell.sh will contain

#!/bin/bash
docker run -it -v /tmp:/tmp -v $(pwd):/code ufoym/deepo python3

Don't forget to make the script executable.

chmod u+x ~/.docker-python-shell.sh

Two remarks on the docker run command:

comments powered by Disqus

Recent posts

See more

Categories

About

This website is a weblog were I write about computer science, machine learning, language learning.