0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

dockerで機械学習(103) 環境構築(3)docker/linux/macos bash スクリプト, ms-dos batchファイル

Last updated at Posted at 2018-10-06

docker

dockerでシェルスクリプトを作るには、何かエディタがあるとよい。

エディタ

# apt install vim

編集

# vi py.sh

拡張子はsh(shell script)

実行権

# chmod +x py.sh

+x で実行権(eXecute)を付与する。

実行

./py.sh ch01

./をつけて、現在のディレクトリのファイルであることを指定。

例題

py.sh
#!/bin/bash
cd $1
for f in *.py 
  do 
    python $f.py
  done
cd ..

というファイルを作成

# ./py.sh ch01
(null): can't open file 'analyze_webstats.py.py': [Errno 2] No such file or directory
(null): can't open file 'gen_webstats.py.py': [Errno 2] No such file or directory
(null): can't open file 'performance_test.py.py': [Errno 2] No such file or directory

# ls ch01
analyze_webstats.py  data  gen_webstats.py  performance_test.py

おお、実行時の.pyが余分だった。

py.sh
#!/bin/bash
cd $1
for f in *.py
  do 
    python $f
  done
cd ..

実行しなおし。

(base) root@fc6d6bfbba64:/BuildingMachineLearningSystemsWithPython# ./py.sh ch01
Traceback (most recent call last):
  File "analyze_webstats.py", line 10, in <module>
    import matplotlib.pyplot as plt
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 15, in <module>
    from .backend_qt5 import (
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/backend_qt5.py", line 19, in <module>
    import matplotlib.backends.qt_editor.figureoptions as figureoptions
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 20, in <module>
    import matplotlib.backends.qt_editor.formlayout as formlayout
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/qt_editor/formlayout.py", line 54, in <module>
    from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/qt_compat.py", line 158, in <module>
    raise ImportError("Failed to import any qt binding")
ImportError: Failed to import any qt binding
Traceback (most recent call last):
  File "gen_webstats.py", line 14, in <module>
    import matplotlib.pyplot as plt
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 15, in <module>
    from .backend_qt5 import (
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/backend_qt5.py", line 19, in <module>
    import matplotlib.backends.qt_editor.figureoptions as figureoptions
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 20, in <module>
    import matplotlib.backends.qt_editor.formlayout as formlayout
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/qt_editor/formlayout.py", line 54, in <module>
    from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
  File "/opt/conda/lib/python3.7/site-packages/matplotlib/backends/qt_compat.py", line 158, in <module>
    raise ImportError("Failed to import any qt binding")
ImportError: Failed to import any qt binding
Traceback (most recent call last):
  File "performance_test.py", line 12, in <module>
    number=10000)
  File "/opt/conda/lib/python3.7/timeit.py", line 232, in timeit
    return Timer(stmt, setup, timer, globals).timeit(number)
  File "/opt/conda/lib/python3.7/timeit.py", line 176, in timeit
    timing = self.inner(it, self.timer)
  File "<timeit-src>", line 6, in inner
NameError: name 'xrange' is not defined

し、し、しまった。python 2.7じゃないとダメだった。

参考資料(reference)

docker 入門
https://qiita.com/kaizen_nagoya/items/2f31319e40ddaa0bf8a5

shell でディレクトリ内のファイルに対してループ処理
https://qiita.com/elzup/items/e839a8c4e815808fb4bc

bashの変数展開によるファイル名や拡張子の取得
https://qiita.com/mriho/items/b30b3a33e8d2e25e94a8

パス文字列からファイル名などを抜き出す
https://qiita.com/ktr_type23/items/94747a4b27e8a630ce48

初心者向けシェルスクリプトの基本コマンドの紹介
https://qiita.com/zayarwinttun/items/0dae4cb66d8f4bd2a337

シェルスクリプトの基礎知識まとめ
https://qiita.com/katsukii/items/383b241209fe96eae6e7

プログラマーの君! 騙されるな! シェルスクリプトはそう書いちゃ駄目だ!! という話
https://qiita.com/piroor/items/77233173707a0baa6360

Ethernet 記事一覧 Ethernet(0)
https://qiita.com/kaizen_nagoya/items/88d35e99f74aefc98794

Wireshark 一覧 wireshark(0)、Ethernet(48)
https://qiita.com/kaizen_nagoya/items/fbed841f61875c4731d0

線網(Wi-Fi)空中線(antenna)(0) 記事一覧(118/300目標)
https://qiita.com/kaizen_nagoya/items/5e5464ac2b24bd4cd001

C++ Support(0) 
https://qiita.com/kaizen_nagoya/items/8720d26f762369a80514

Coding Rules(0) C Secure , MISRA and so on
https://qiita.com/kaizen_nagoya/items/400725644a8a0e90fbb0

Autosar Guidelines C++14 example code compile list(1-169)
https://qiita.com/kaizen_nagoya/items/8ccbf6675c3494d57a76

Error一覧(C/C++, python, bash...) Error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8

なぜdockerで機械学習するか 書籍・ソース一覧作成中 (目標100)
https://qiita.com/kaizen_nagoya/items/ddd12477544bf5ba85e2

言語処理100本ノックをdockerで。python覚えるのに最適。:10+12
https://qiita.com/kaizen_nagoya/items/7e7eb7c543e0c18438c4

プログラムちょい替え(0)一覧:4件
https://qiita.com/kaizen_nagoya/items/296d87ef4bfd516bc394

一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39

プログラマが知っていると良い「公序良俗」
https://qiita.com/kaizen_nagoya/items/9fe7c0dfac2fbd77a945

小川清最終講義、小川清最終講義(再)計画, Ethernet(100) 英語(100) 安全(100)
https://qiita.com/kaizen_nagoya/items/e2df642e3951e35e6a53

文書履歴

ver. 0.10 初稿 20181006
ver. 0.11 番号変更、参考文献追記 20181028

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?