docker
Python3
apt-get
python2.7
言語処理100本ノック

言語処理100本ノック 2015(python) 動作確認docker環境構築

言語処理100本ノック 2015(python) 動作確認環境構築

言語処理100本ノック2015
http://www.cl.ecei.tohoku.ac.jp/nlp100/

取り組み始めたのが2018年に入ってから。
過去の資料を動作確認しながら、課題と教訓を整理しようと努力中。

言語処理100本ノック 2015(python) 落ち穂拾い 第1章: 準備運動 00, 01, 02, 03,04
https://qiita.com/kaizen_nagoya/items/ee1b625b0b65cd63d42a

Python2系とPython3系の例がある。

切り貼り、環境を切り替えたりしているうちに操作間違いの回数が増えてきた。
両方を試す環境を別々に構築。dockerを利用。
macOS 10.13.3(他のOSでも順次実行予定)

Python3

最初の2つのコマンドはそのまま入力。
最後のdocker runは、-itの次の数字を、docker imagesで出てきた数字に置き換えて実行

python3
$ docker pull python:3.6
$ docker images
REPOSITORY                                              TAG                 IMAGE ID            CREATED             SIZE数字
python                                                  3.6                 efb6baa1169f        12 days ago         691MB

$ docker run --name python36 -it efb6baa1169f /bin/bash

Viエディタでファイルを保存するのであれば、次の4つのapt-get コマンドを実施。my.pyという名前でpythonスクリプトを作ることを想定。

apt-get
# apt-get update
# apt-get upgrade
# apt-get install sudo
# sudo apt-get install vim
# vi my.py

[I]を押し、[command]+[V](macOSの場合), [ESC][W][Q]

python
# python my.py

Python2

最初の2つのコマンドはそのまま入力。
最後のdocker runは、-itの次の数字を、docker imagesで出てきた数字に置き換えて実行

python2
$ docker pull python:2.7
$ docker images
REPOSITORY                                              TAG                 IMAGE ID            CREATED             SIZE                                                  python                                                  2.7                 2863c80c418c        2 weeks ago         679MB

$ docker run --name python27 -it  2863c80c418c /bin/bash

Viエディタでファイルを保存するのであれば、次の4つのapt-get コマンドを実施。my.pyという名前でpythonスクリプトを作ることを想定。

apt-get
# apt-get update
# apt-get upgrade
# apt-get install sudo
# sudo apt-get install vim
# vi my.py

[I]を押し、[command]+[V](macOSの場合), [ESC][W][Q]

python
# python my.py

導入版構成確認。

python3

python3
# python -v
import _frozen_importlib # frozen
import _imp # builtin
import sys # builtin
import '_warnings' # <class '_frozen_importlib.BuiltinImporter'>
import '_thread' # <class '_frozen_importlib.BuiltinImporter'>
import '_weakref' # <class '_frozen_importlib.BuiltinImporter'>
import '_frozen_importlib_external' # <class '_frozen_importlib.FrozenImporter'>
import '_io' # <class '_frozen_importlib.BuiltinImporter'>
import 'marshal' # <class '_frozen_importlib.BuiltinImporter'>
import 'posix' # <class '_frozen_importlib.BuiltinImporter'>
import _thread # previously loaded ('_thread')
import '_thread' # <class '_frozen_importlib.BuiltinImporter'>
import _weakref # previously loaded ('_weakref')
import '_weakref' # <class '_frozen_importlib.BuiltinImporter'>
# installing zipimport hook
import 'zipimport' # <class '_frozen_importlib.BuiltinImporter'>
# installed zipimport hook
# code object from /usr/local/lib/python3.6/encodings/__init__.py
# created '/usr/local/lib/python3.6/encodings/__pycache__/__init__.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/encodings/__pycache__/__init__.cpython-36.pyc'
# code object from /usr/local/lib/python3.6/codecs.py
# created '/usr/local/lib/python3.6/__pycache__/codecs.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/codecs.cpython-36.pyc'
import '_codecs' # <class '_frozen_importlib.BuiltinImporter'>
import 'codecs' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b75e2588>
# code object from /usr/local/lib/python3.6/encodings/aliases.py
# created '/usr/local/lib/python3.6/encodings/__pycache__/aliases.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/encodings/__pycache__/aliases.cpython-36.pyc'
import 'encodings.aliases' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b751ea20>
import 'encodings' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b768f860>
# code object from /usr/local/lib/python3.6/encodings/utf_8.py
# created '/usr/local/lib/python3.6/encodings/__pycache__/utf_8.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/encodings/__pycache__/utf_8.cpython-36.pyc'
import 'encodings.utf_8' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b751e160>
import '_signal' # <class '_frozen_importlib.BuiltinImporter'>
# code object from /usr/local/lib/python3.6/encodings/latin_1.py
# created '/usr/local/lib/python3.6/encodings/__pycache__/latin_1.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/encodings/__pycache__/latin_1.cpython-36.pyc'
import 'encodings.latin_1' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b75f9ba8>
# code object from /usr/local/lib/python3.6/io.py
# created '/usr/local/lib/python3.6/__pycache__/io.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/io.cpython-36.pyc'
# code object from /usr/local/lib/python3.6/abc.py
# created '/usr/local/lib/python3.6/__pycache__/abc.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/abc.cpython-36.pyc'
# code object from /usr/local/lib/python3.6/_weakrefset.py
# created '/usr/local/lib/python3.6/__pycache__/_weakrefset.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/_weakrefset.cpython-36.pyc'
import '_weakrefset' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b7600780>
import 'abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b75fab38>
import 'io' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b75fa160>
# code object from /usr/local/lib/python3.6/site.py
# created '/usr/local/lib/python3.6/__pycache__/site.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/site.cpython-36.pyc'
# code object from /usr/local/lib/python3.6/os.py
# created '/usr/local/lib/python3.6/__pycache__/os.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/os.cpython-36.pyc'
import 'errno' # <class '_frozen_importlib.BuiltinImporter'>
# code object from /usr/local/lib/python3.6/stat.py
# created '/usr/local/lib/python3.6/__pycache__/stat.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/stat.cpython-36.pyc'
import '_stat' # <class '_frozen_importlib.BuiltinImporter'>
import 'stat' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b75f3eb8>
# code object from /usr/local/lib/python3.6/posixpath.py
# created '/usr/local/lib/python3.6/__pycache__/posixpath.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/posixpath.cpython-36.pyc'
# code object from /usr/local/lib/python3.6/genericpath.py
# created '/usr/local/lib/python3.6/__pycache__/genericpath.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/genericpath.cpython-36.pyc'
import 'genericpath' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b753d7f0>
import 'posixpath' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b753d860>
# code object from /usr/local/lib/python3.6/_collections_abc.py
# created '/usr/local/lib/python3.6/__pycache__/_collections_abc.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/_collections_abc.cpython-36.pyc'
import '_collections_abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b760a0f0>
import 'os' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b75e8a58>
# code object from /usr/local/lib/python3.6/_sitebuiltins.py
# created '/usr/local/lib/python3.6/__pycache__/_sitebuiltins.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/_sitebuiltins.cpython-36.pyc'
import '_sitebuiltins' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b7560cf8>
# code object from /usr/local/lib/python3.6/sysconfig.py
# created '/usr/local/lib/python3.6/__pycache__/sysconfig.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/sysconfig.cpython-36.pyc'
import 'sysconfig' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b75e87b8>
# code object from /usr/local/lib/python3.6/_sysconfigdata_m_linux_x86_64-linux-gnu.py
# created '/usr/local/lib/python3.6/__pycache__/_sysconfigdata_m_linux_x86_64-linux-gnu.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/_sysconfigdata_m_linux_x86_64-linux-gnu.cpython-36.pyc'
import '_sysconfigdata_m_linux_x86_64-linux-gnu' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b7546e10>
import 'site' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b75e8358>
Python 3.6.5 (default, Mar 31 2018, 01:15:58) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
# extension module 'readline' loaded from '/usr/local/lib/python3.6/lib-dynload/readline.cpython-36m-x86_64-linux-gnu.so'
# extension module 'readline' executed from '/usr/local/lib/python3.6/lib-dynload/readline.cpython-36m-x86_64-linux-gnu.so'
import 'readline' # <_frozen_importlib_external.ExtensionFileLoader object at 0x7fb5b74957f0>
import 'atexit' # <class '_frozen_importlib.BuiltinImporter'>
# code object from /usr/local/lib/python3.6/rlcompleter.py
# created '/usr/local/lib/python3.6/__pycache__/rlcompleter.cpython-36.pyc'
# wrote '/usr/local/lib/python3.6/__pycache__/rlcompleter.cpython-36.pyc'
import 'rlcompleter' # <_frozen_importlib_external.SourceFileLoader object at 0x7fb5b7495908>

python2

python2
# python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/local/lib/python2.7/site.pyc matches /usr/local/lib/python2.7/site.py
import site # precompiled from /usr/local/lib/python2.7/site.pyc
# /usr/local/lib/python2.7/os.pyc matches /usr/local/lib/python2.7/os.py
import os # precompiled from /usr/local/lib/python2.7/os.pyc
import errno # builtin
import posix # builtin
# /usr/local/lib/python2.7/posixpath.pyc matches /usr/local/lib/python2.7/posixpath.py
import posixpath # precompiled from /usr/local/lib/python2.7/posixpath.pyc
# /usr/local/lib/python2.7/stat.pyc matches /usr/local/lib/python2.7/stat.py
import stat # precompiled from /usr/local/lib/python2.7/stat.pyc
# /usr/local/lib/python2.7/genericpath.pyc matches /usr/local/lib/python2.7/genericpath.py
import genericpath # precompiled from /usr/local/lib/python2.7/genericpath.pyc
# /usr/local/lib/python2.7/warnings.pyc matches /usr/local/lib/python2.7/warnings.py
import warnings # precompiled from /usr/local/lib/python2.7/warnings.pyc
# /usr/local/lib/python2.7/linecache.pyc matches /usr/local/lib/python2.7/linecache.py
import linecache # precompiled from /usr/local/lib/python2.7/linecache.pyc
# /usr/local/lib/python2.7/types.pyc matches /usr/local/lib/python2.7/types.py
import types # precompiled from /usr/local/lib/python2.7/types.pyc
# /usr/local/lib/python2.7/UserDict.pyc matches /usr/local/lib/python2.7/UserDict.py
import UserDict # precompiled from /usr/local/lib/python2.7/UserDict.pyc
# /usr/local/lib/python2.7/_abcoll.pyc matches /usr/local/lib/python2.7/_abcoll.py
import _abcoll # precompiled from /usr/local/lib/python2.7/_abcoll.pyc
# /usr/local/lib/python2.7/abc.pyc matches /usr/local/lib/python2.7/abc.py
import abc # precompiled from /usr/local/lib/python2.7/abc.pyc
# /usr/local/lib/python2.7/_weakrefset.pyc matches /usr/local/lib/python2.7/_weakrefset.py
import _weakrefset # precompiled from /usr/local/lib/python2.7/_weakrefset.pyc
import _weakref # builtin
# /usr/local/lib/python2.7/copy_reg.pyc matches /usr/local/lib/python2.7/copy_reg.py
import copy_reg # precompiled from /usr/local/lib/python2.7/copy_reg.pyc
# /usr/local/lib/python2.7/traceback.pyc matches /usr/local/lib/python2.7/traceback.py
import traceback # precompiled from /usr/local/lib/python2.7/traceback.pyc
# /usr/local/lib/python2.7/sysconfig.pyc matches /usr/local/lib/python2.7/sysconfig.py
import sysconfig # precompiled from /usr/local/lib/python2.7/sysconfig.pyc
# /usr/local/lib/python2.7/re.pyc matches /usr/local/lib/python2.7/re.py
import re # precompiled from /usr/local/lib/python2.7/re.pyc
# /usr/local/lib/python2.7/sre_compile.pyc matches /usr/local/lib/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/local/lib/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/local/lib/python2.7/sre_parse.pyc matches /usr/local/lib/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/local/lib/python2.7/sre_parse.pyc
# /usr/local/lib/python2.7/sre_constants.pyc matches /usr/local/lib/python2.7/sre_constants.py
import sre_constants # precompiled from /usr/local/lib/python2.7/sre_constants.pyc
dlopen("/usr/local/lib/python2.7/lib-dynload/_locale.so", 2);
import _locale # dynamically loaded from /usr/local/lib/python2.7/lib-dynload/_locale.so
# /usr/local/lib/python2.7/_sysconfigdata.pyc matches /usr/local/lib/python2.7/_sysconfigdata.py
import _sysconfigdata # precompiled from /usr/local/lib/python2.7/_sysconfigdata.pyc
import encodings # directory /usr/local/lib/python2.7/encodings
# /usr/local/lib/python2.7/encodings/__init__.pyc matches /usr/local/lib/python2.7/encodings/__init__.py
import encodings # precompiled from /usr/local/lib/python2.7/encodings/__init__.pyc
# /usr/local/lib/python2.7/codecs.pyc matches /usr/local/lib/python2.7/codecs.py
import codecs # precompiled from /usr/local/lib/python2.7/codecs.pyc
import _codecs # builtin
# /usr/local/lib/python2.7/encodings/aliases.pyc matches /usr/local/lib/python2.7/encodings/aliases.py
import encodings.aliases # precompiled from /usr/local/lib/python2.7/encodings/aliases.pyc
# /usr/local/lib/python2.7/encodings/utf_8.pyc matches /usr/local/lib/python2.7/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/local/lib/python2.7/encodings/utf_8.pyc
Python 2.7.14 (default, Mar 14 2018, 18:21:57) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/usr/local/lib/python2.7/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /usr/local/lib/python2.7/lib-dynload/readline.so

参考資料

Docker for Mac におけるコンテナからホストへのアクセスについて 斉藤直希,名古屋市工業研究所, 20180412

Docker hub, python
https://hub.docker.com/_/python/

Dockerの環境構築 part.2(window7にて),松原和音,名古屋市工業研究所, 20180412

Dockerでpython3環境を準備する
https://qiita.com/RyoMa_0923/items/7c0b22dd3f284472e18d

Docker上のCentOSにPython3と、関連ライブラリpip, virtualenvとフレームワークDjango, bottle, Flaskのインストール!これらをまとめたDockerfile付き!
https://qiita.com/RyosukeKamei/items/eca9687162b7fe122094

RPiでの検出器の作成, 間瀬剛,名古屋市工業研究所, 20180412

文書履歴

ver. 0.10 初稿 20180412
ver. 0.11 apt-get vim 追記 20180412
ver. 0.12 sudo追記 20180413
ver. 0.13 「最初の2つのコマンドはそのまま入力。
最後のdocker runは、-itの次の数字を、docker imagesで出てきた数字に置き換えて実行」を追記 20180419