GCPトレーニング「Big Data & ML Fundamentals Lab 2: Interact with Google Cloud Storage v1.2 」でのエラー対応
上記のエラーが出てトレーニングが進まないのでその対応方法を調べた
python transform.pyを実行するとエラーする
google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ python transform.pyTraceback (most recent call last): File "transform.py", line 13, in <module> import numpy as npImportError: No module named numpynumpyパッケージの解決までの準備
google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ curl -O https://bootstrap.pypa.io/ez_setup.pygoogle1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ sudo python ./ez_setup.pygoogle1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ sudo easy_install pipnumpyパッケージのインストール
google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ sudo pip install numpyCollecting numpy Downloading https://files.pythonhosted.org/packages/40/c5/f1ed15dd931d6667b40f1ab1c2fe1f26805fc2b6c3e25e45664f838de9d0/numpy-1.15.2-cp27-cp27mu-manylinux1_x86_64.whl (13.8MB) 100% |████████████████████████████████| 13.8MB 1.7MB/sInstalling collected packages: numpySuccessfully installed numpy-1.15.2matplotlibパッケージでエラー
google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ python transform.pyTraceback (most recent call last): File "transform.py", line 14, in <module> import su as mplImportError: No module named matplotlibmatplotlibパッケージをインストール
pipではインストールできない
google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ sudo pip install matplotlibパッケージでインストール
google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ sudo apt-get install -y python-subprocess32Reading package lists... DoneBuilding dependency treeReading state information... DoneThe following NEW packages will be installed: python-subprocess320 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.Need to get 28.9 kB of archives.After this operation, 119 kB of additional disk space will be used.Get:1 http://deb.debian.org/debian stretch/main amd64 python-subprocess32 amd64 3.2.7-2 [28.9 kB]Fetched 28.9 kB in 0s (503 kB/s)Selecting previously unselected package python-subprocess32.(Reading database ... 42570 files and directories currently installed.)Preparing to unpack .../python-subprocess32_3.2.7-2_amd64.deb ...Unpacking python-subprocess32 (3.2.7-2) ...Setting up python-subprocess32 (3.2.7-2) ...google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ sudo pip install matplotlibCollecting matplotlib Using cached https://files.pythonhosted.org/packages/59/08/04933377dc4500e3698e93f9113dc3624874e0914f4c85767ecb5b389084/matplotlib-2.2.3-cp27-cp27mu-manylinux1_x86_64.whlRequirement already satisfied: numpy>=1.7.1 in /usr/local/lib/python2.7/dist-packages (from matplotlib) (1.15.2)Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python2.7/dist-packages (from matplotlib) (0.10.0)Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python2.7/dist-packages (from matplotlib) (1.0.1)Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python2.7/dist-packages (from matplotlib) (2.7.3)Requirement already satisfied: six>=1.10 in /usr/lib/python2.7/dist-packages (from matplotlib) (1.10.0)Requirement already satisfied: pytz in /usr/local/lib/python2.7/dist-packages (from matplotlib) (2018.5)Requirement already satisfied: subprocess32 in /usr/lib/python2.7/dist-packages (from matplotlib) (3.2.7)Collecting backports.functools-lru-cache (from matplotlib) Using cached https://files.pythonhosted.org/packages/03/8e/2424c0e65c4a066e28f539364deee49b6451f8fcd4f718fefa50cc3dcf48/backports.functools_lru_cache-1.5-py2.py3-none-any.whlCollecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib) Using cached https://files.pythonhosted.org/packages/42/47/e6d51aef3d0393f7d343592d63a73beee2a8d3d69c22b053e252c6cfacd5/pyparsing-2.2.1-py2.py3-none-any.whlRequirement already satisfied: setuptools in /usr/local/lib/python2.7/dist-packages/setuptools-33.1.1-py2.7.egg (from kiwisolver>=1.0.1->matplotlib) (33.1.1)Installing collected packages: backports.functools-lru-cache, pyparsing, matplotlibSuccessfully installed backports.functools-lru-cache-1.5 matplotlib-2.2.3 pyparsing-2.2.1basemapパッケージでエラー
google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ python transform.pyTraceback (most recent call last): File "transform.py", line 17, in <module> from mpl_toolkits.basemap import BasemapImportError: No module named basemapbasemapをインストール
sudo apt install python-mpltoolkits.basemapvimで__init__.pyのメソッドを編集する
google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ sudo vim /usr/lib/python2.7/dist-packages/mpl_toolkits/basemap/__init__.pyfill_color = ax.get_axis_bgcolor() ↓fill_color = ax.get_fc()参考はこちらを。 https://github.com/matplotlib/matplotlib/issues/7808/ https://qiita.com/nigo1973/items/5408d3b4a5f69591f835
transform.pyを実行できるようになる
google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ python transform.py{'lat': 69.5363, 'timestamp': '2018-09-24T13:17:10.233Z', 'magnitude': 2.2, 'lon': -144.0685}/usr/lib/python2.7/dist-packages/mpl_toolkits/basemap/__init__.py:3260: MatplotlibDeprecationWarning: The ishold function was deprecated in version 2.0. b = ax.ishold()/usr/lib/python2.7/dist-packages/mpl_toolkits/basemap/__init__.py:3269: MatplotlibDeprecationWarning: axes.hold isdeprecated. See the API Changes document (http://matplotlib.org/api/api_changes.html) for more details. ax.hold(b)google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ ls -altotal 1416drwxr-xr-x 3 google1117239_student google1117239_student 4096 Sep 24 13:26 .drwxr-xr-x 8 google1117239_student google1117239_student 4096 Sep 24 12:42 ..-rw-r--r-- 1 google1117239_student google1117239_student 637 Sep 24 12:42 commands.sh-rw-r--r-- 1 google1117239_student google1117239_student 370625 Sep 24 12:35 earthquakes.csv-rw-r--r-- 1 google1117239_student google1117239_student 751 Sep 24 12:42 earthquakes.htm-rw-r--r-- 1 google1117239_student google1117239_student 321866 Sep 24 13:26 earthquakes.png-rw-r--r-- 1 google1117239_student google1117239_student 12537 Sep 24 12:45 ez_setup.py-rwxr-xr-x 1 google1117239_student google1117239_student 759 Sep 24 12:42 ingest.sh-rwxr-xr-x 1 google1117239_student google1117239_student 707 Sep 24 12:42 install_missing.shdrwxr-xr-x 2 google1117239_student google1117239_student 4096 Sep 24 12:42 scheduled-rw-r--r-- 1 google1117239_student google1117239_student 702770 Sep 24 12:45 setuptools-33.1.1.zip-rwxr-xr-x 1 google1117239_student google1117239_student 3058 Sep 24 12:42 transform.pygoogle1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ gsutil cp earthquakes.* gs://<YOUR-BUCKET>/earthquakes/-bash: YOUR-BUCKET: No such file or directorygoogle1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ gsutil cp earthquakes.* gs://qwiklabs-gcp-3c9c336ef09395ac/earthquakes/Copying file://earthquakes.csv [Content-Type=text/csv]...Copying file://earthquakes.htm [Content-Type=text/html]...Copying file://earthquakes.png [Content-Type=image/png]...\ [3 files][677.0 KiB/677.0 KiB]Operation completed over 3 objects/677.0 KiB.google1117239_student@instance-1:~/training-data-analyst/CPB100/lab2b$ gsutil acl ch -u AllUsers:R gs://qwiklabs-gcp-3c9c336ef09395ac/earthquakes/*Updated ACL on gs://qwiklabs-gcp-3c9c336ef09395ac/earthquakes/earthquakes.csvUpdated ACL on gs://qwiklabs-gcp-3c9c336ef09395ac/earthquakes/earthquakes.htmUpdated ACL on gs://qwiklabs-gcp-3c9c336ef09395ac/earthquakes/earthquakes.png最後に
動画の9:30ごろから編集する流れがあったのでちょい困る。。。 悩んで対応しなくてもよかった。