ラベル Python3 の投稿を表示しています。 すべての投稿を表示
ラベル Python3 の投稿を表示しています。 すべての投稿を表示

2022年1月25日火曜日

TensorFlowでnot use cuDNN kernels警告メッセージ

 Amazon SageMaker Studio LabにTensor Flow2.6.2をインストールしてLSTMを使用して学習させてみたところ以下のエラーメッセージが表示

WARNING:tensorflow:Layer lstm will not use cuDNN kernels since it doesn't meet the criteria. It will use a generic GPU kernel as fallback when running on GPU.

WEBで翻訳させてみると「警告:tensorflow:Layer lstm_2は、基準を満たしていないため、cuDNNカーネルを使用しません。 GPUで実行する場合、フォールバックとして汎用GPUカーネルを使用します。」

基準は公式ドキュメントに記載があり以下のようです。

The requirements to use the cuDNN implementation are:

activation == tanh

recurrent_activation == sigmoid

recurrent_dropout == 0

unroll is False

use_bias is True

Inputs, if use masking, are strictly right-padded.

Eager execution is enabled in the outermost context.

    (修正前)

    m.add(LSTM(128, activation='relu',unroll=False,use_bias=True, input_shape=(nda_x_training.shape[1], nda_x_training.shape[2]))) 


    (修正後)

    m.add(LSTM(128, dropout=0.5,recurrent_dropout=0,activation='tanh',recurrent_activation='sigmoid',unroll=False,use_bias=True, input_shape=(nda_x_training.shape[1], nda_x_training.shape[2]))) 

 無事警告メッセージは表示しなくなったのでGPUが使用されたのかな。

2021年11月15日月曜日

matplotlibの代わりにseabornでグラフを描く準備

 matplotlibではなくseabornでグラフを描いたほうが見た目がよさそうなのでインストールとテスト描画をしてみました。


【インストール】

>pip install seaborn


どうやら0.11.2がインストールされたようです。

【テストデータ】

今回は昔の日経平均を表示させてみました、データはDataFraame形式でカラムは日経の値の'N225'と日時の'date'

(データイメージ)

【グラフ描画】

簡単な折れ線グラフを試してみました。引数にデータを格納している変数、x軸、y軸に表示させる対象のカラム、kindは線の種類

>import seaborn as sns
>sns.relplot(x='date',y='N225',data=df_raw_dataset,kind='line')

ちょっとこのグラフだとseabornにしたメリットが感じられないかもしれないけれどとりあえ描画できたので詳細はおいおい

【distplot関数について】

seabornを紹介されているサイトでよく見かけるdistplotを使用すると以下の様な警告がでるようです。将来廃止されるようで非推奨の関数のようです

FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).


2021年10月14日木曜日

【matplotlib】FutureWarning: Support for multi-dimensional indexing (e.g. `obj[:, None]`) is deprecated

matplotlibでグラフ表示をさせていたところ以下の警告メッセージ

FutureWarning: Support for multi-dimensional indexing (e.g. `obj[:, None]`) is deprecated and will be removed in a future version.  Convert to a numpy array before indexing instead.

どうやら非推奨な使い方?をしているようです。

グラフデータに<class 'pandas.core.indexes.datetimes.DatetimeIndex'>や<class 'pandas.core.series.Series'>型のデータを渡しているだけなのですが・・・。

【Version】
matplotlib:3.0.2
pandas:1.3.3
numpy:1.21.2

色々調べて結局valuesかto_numpy()で<class 'numpy.ndarray'>型に変換して渡すことで解決できました。(valuesよりto_numpy()が推奨されているらしい)

2021年10月12日火曜日

pandas-datareaderで株価、市場指標を取得してみる

Pythonで機械学習を勉強している時にテストデータとして株価か市場指標を使用と思い取得方法を調べてみるとpandas-datareaderライブラリが便利そうなことが判明

早速インストール

・インストールログ

pip install pandas-datareader

Defaulting to user installation because normal site-packages is not writeable

Collecting pandas-datareader

  Downloading pandas_datareader-0.10.0-py3-none-any.whl (109 kB)

     |████████████████████████████████| 109 kB 536 kB/s 

Collecting lxml

  Downloading lxml-4.6.3-cp37-cp37m-manylinux2014_aarch64.whl (6.7 MB)

     |████████████████████████████████| 6.7 MB 1.4 MB/s 

Requirement already satisfied: requests>=2.19.0 in ./.local/lib/python3.7/site-packages (from pandas-datareader) (2.26.0)

Requirement already satisfied: pandas>=0.23 in ./.local/lib/python3.7/site-packages (from pandas-datareader) (1.3.3)

Requirement already satisfied: numpy>=1.17.3 in ./.local/lib/python3.7/site-packages (from pandas>=0.23->pandas-datareader) (1.21.2)

Requirement already satisfied: pytz>=2017.3 in ./.local/lib/python3.7/site-packages (from pandas>=0.23->pandas-datareader) (2021.1)

Requirement already satisfied: python-dateutil>=2.7.3 in ./.local/lib/python3.7/site-packages (from pandas>=0.23->pandas-datareader) (2.8.1)

Requirement already satisfied: six>=1.5 in ./.local/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas>=0.23->pandas-datareader) (1.15.0)

Requirement already satisfied: idna<4,>=2.5 in ./.local/lib/python3.7/site-packages (from requests>=2.19.0->pandas-datareader) (3.2)

Requirement already satisfied: certifi>=2017.4.17 in ./.local/lib/python3.7/site-packages (from requests>=2.19.0->pandas-datareader) (2021.5.30)

Requirement already satisfied: urllib3<1.27,>=1.21.1 in ./.local/lib/python3.7/site-packages (from requests>=2.19.0->pandas-datareader) (1.26.6)

Requirement already satisfied: charset-normalizer~=2.0.0 in ./.local/lib/python3.7/site-packages (from requests>=2.19.0->pandas-datareader) (2.0.6)

Installing collected packages: lxml, pandas-datareader

Successfully installed lxml-4.6.3 pandas-datareader-0.10.0


・取得テスト

国内国内のトヨタ(7203.T)の株価を取得してみる

python3

Python 3.7.3 (default, Jan 22 2021, 20:04:44) 

[GCC 8.3.0] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> from pandas_datareader import data

>>> df = data.DataReader('7203.T','yahoo')

>>> df.head(5)


                   High          Low  ...      Volume   Adj Close

Date                                  ...                        

2016-10-12  1201.199951  1188.000000  ...  25115500.0  962.449158

2016-10-13  1211.599976  1190.800049  ...  39343500.0  964.387817

2016-10-14  1199.400024  1184.400024  ...  31210500.0  968.265503

2016-10-17  1212.599976  1198.199951  ...  28159500.0  974.243408

2016-10-18  1202.800049  1189.400024  ...  27223000.0  967.780762


[5 rows x 6 columns]


・複数銘柄、取得期間指定して取得してみる

df = data.DataReader(['2914.T','9513.T'],'yahoo','2021-10-01','2021-10-10')

>>> df.head(5)

Attributes Adj Close           Close          ...    Open           Volume         

Symbols       2914.T  9513.T  2914.T  9513.T  ...  2914.T  9513.T   2914.T   9513.T

Date                                          ...                                  

2021-10-01    2172.5  1597.0  2172.5  1597.0  ...  2174.0  1605.0  4596700   892700

2021-10-04    2159.5  1629.0  2159.5  1629.0  ...  2180.5  1608.0  4433800  1266300

2021-10-05    2165.0  1612.0  2165.0  1612.0  ...  2156.0  1626.0  3440000  1014500

2021-10-06    2193.0  1655.0  2193.0  1655.0  ...  2176.5  1625.0  5366200  1310600

2021-10-07    2181.0  1636.0  2181.0  1636.0  ...  2190.5  1658.0  2994300   748400


[5 rows x 12 columns]


・市場指標(日経平均)を取得してみる

df = data.DataReader(['^N225'],'yahoo','2021-10-01','2021-10-10')

>>> df.head(5)

Attributes     Adj Close         Close  ...          Open     Volume

Symbols            ^N225         ^N225  ...         ^N225      ^N225

Date                                    ...                         

2021-10-01  28771.070312  28771.070312  ...  29235.109375   82200000

2021-10-04  28444.890625  28444.890625  ...  29044.470703   76400000

2021-10-05  27822.119141  27822.119141  ...  28050.390625   88200000

2021-10-06  27528.869141  27528.869141  ...  28033.910156  100200000

2021-10-07  27678.210938  27678.210938  ...  27665.970703   79600000


[5 rows x 6 columns]


・米国株式情報を取得してみる

df = data.DataReader(['AMD'],'yahoo','2021-10-01','2021-10-10')

>>> df.head(3)

Attributes   Adj Close       Close        High         Low        Open    Volume

Symbols            AMD         AMD         AMD         AMD         AMD       AMD

Date                                                                            

2021-09-30  102.900002  102.900002  104.440002  101.989998  102.080002  57588500

2021-10-01  102.449997  102.449997  103.000000  100.639999  102.599998  41491600

2021-10-04  100.339996  100.339996  101.849998   99.820000  101.739998  41967100


・その他銘柄/指標

【NASDAQ】^IXIC

【S&P500】^GSPC

【NYダウ】^DJI


・取得できるカラム情報

 Adj Close:調整後終値

Close:終値

High:高値

Low:安値

Open:始値

Volume:出来高

・その他

情報の取得サイトによって取サーバに負荷がかかるため取得禁止の場合もあるので事前に確認が必要のようです。

2021年9月26日日曜日

【Keras2.6】ImportError: cannot import name 'Adam' from 'keras.optimizers'

keras2.6でAdamをインポートすると以下のエラーがでました

ImportError: cannot import name 'Adam' from 'keras.optimizers'

以前のバージョンから変わったようです。

ProgrammerAHのブログを参考して以下の通りに修正

(修正前)
from keras.optimizers import Adam

(修正後)
from keras.optimizers import adam_v2

実際Adamを使用しているところも合わせて修正

(修正前)
model.compile(loss='categorical_crossentropy', optimizer=Adam(), metrics=['accuracy']) 

(修正後)
model.compile(loss='categorical_crossentropy', optimizer=adam_v2.Adam(), metrics=['accuracy']) 

参考書とのバージョン差異がポツリポツリと・・・勉強中のみとしてはこういうのは辛いかも。

2021年9月21日火曜日

keras2.6でAttributeError: module 'keras.optimizers' has no attribute 'SGD'

参考書通りにコーディングしてみたところエラー・・・・。
たしかに環境は違うけれど困る。 

【エラーメッセージ】
>>> sgd = optimizers.SGD(lr=0.01, clipnorm=1.)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'keras.optimizers' has no attribute 'SGD'


>>> import keras
>>> keras.__version__
'2.6.0'>>> from keras import optimizers

dirコマンドでoptimizersを確認すると確かにSGDはなく、仕様が変更されたのかな・・・。
検索しても意外に情報が少なくもしかしてあたりまえ?常識

とりあえず無事別の方法を発見、ついでにオプションのlrは非推奨になったようで変わりにlearning_rateを使用するらしい。

【代替え?】
>>> sgd = optimizers.gradient_descent_v2.SGD(lr=0.001, clipnorm=1.)
/home/xx/.local/lib/python3.7/site-packages/keras/optimizer_v2/optimizer_v2.py:356: UserWarning: The `lr` argument is deprecated, use `learning_rate` instead.
  "The `lr` argument is deprecated, use `learning_rate` instead.")

--------------------------------------------

【追記】

kerasはtensorflow.kerasとしてTensorFlow2にで組み込まれたようです。単独のkerasの使い方が変わっているようです。

2021年9月19日日曜日

【TensorFlow】Chromebook(ARM64)のLinux(Debian)にPython3.7+TensorFlow2.6.0+ keras

 Pandasのインストールも問題なく終わったので早速TensorFlowをインストールしようとpipコマンドで実行してみると。

pip install tensorflow

Defaulting to user installation because normal site-packages is not writeable

ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)

ERROR: No matching distribution found for tensorflow

対象のバージョンがない?

調べてみるとこういうケースはあるようでPtyhon3.7は以前は対応していなかったらしいですが調べていくうちに現在は対応していることは判明、一安心。

どうやら自分の環境に合うパッケージ(whl)ファイルをダウンロードしてインストールすれば良さそうということが分かりました。

■端末構成

ASUS Chromebook Detachable CM3

$cat /etc/issue
Debian GNU/Linux 10 \n \l

コードネームはbuster

$lscpu
Architecture:        aarch64
Byte Order:          Little Endian
CPU(s):              8
On-line CPU(s) list: 0-7
Thread(s) per core:  1
Core(s) per socket:  4
Socket(s):           2
Vendor ID:           ARM
Model:               4
Model name:          Cortex-A53
Stepping:            r0p4
BogoMIPS:            26.00
Flags:               fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid

Python 3.7.3 (default, Jan 22 2021, 20:04:44)

■numpyの最新化

ダウンロードするパッケージを選ぶ際にnumpyのバージョンらしい数字で分れていたので事前に最新化
・バージョン確認
$pip list --outdated
Package           Version Latest Type
----------------- ------- ------ -----
numpy             1.20.3  1.21.2 wheel

・バージョンアップ
$pip install --upgrade numpy

■ TensorFlowパッケージファイルダウンロード

ダウンロードサイト:https://github.com/PINTO0309/Tensorflow-bin

事前に調べたArchitectureとPythonのバージョンとnumpyのバージョンからtensorflow-2.6.0-cp37-none-linux_aarch64_numpy1211_download.shを選択

リンクからwhlファイルをダウンロードできるわけではなさそうで上記のshファイルをダウンロードするらしい。
ただダウンロード方法が分からずリンク先にあるshファイルのソースをコピーして適当に作成したローカルファイル(/tmp/download.sh)にソースをペースト

(https://github.com/PINTO0309/Tensorflow-binから引用) 

#!/bin/bash

curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1XnV8W38HGW4PmENmfQA5-5NrQ84SsTqX" > /dev/null
CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1XnV8W38HGW4PmENmfQA5-5NrQ84SsTqX" -o tensorflow-2.6.0-cp37-none-linux_aarch64.whl
echo Download finished.


download.shに実行権を付与した後download.shを実行して無事tensorflow-2.6.0-cp37-none-linux_aarch64.whlを入手

■TensorFlowインストール

さっそくインストールしてみると
pip install tensorflow-2.6.0-cp37-none-linux_aarch64.whl

(エラー)
Defaulting to user installation because normal site-packages is not writeable
Processing ./tensorflow-2.6.0-cp37-none-linux_aarch64.whl
Collecting h5py~=3.1.0
  Downloading h5py-3.1.0.tar.gz (371 kB)
     |████████████████████████████████| 371 kB 1.5 MB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Collecting tensorflow-estimator~=2.6
  Downloading tensorflow_estimator-2.6.0-py2.py3-none-any.whl (462 kB)
     |████████████████████████████████| 462 kB 2.3 MB/s
Collecting wheel~=0.35
  Using cached wheel-0.37.0-py2.py3-none-any.whl (35 kB)
Collecting six~=1.15.0
  Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting clang~=5.0
  Downloading clang-5.0.tar.gz (30 kB)
Collecting keras-preprocessing~=1.1.2
  Downloading Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)
     |████████████████████████████████| 42 kB 284 kB/s
Collecting flatbuffers~=1.12.0
  Downloading flatbuffers-1.12-py2.py3-none-any.whl (15 kB)
Collecting keras~=2.6
  Downloading keras-2.6.0-py2.py3-none-any.whl (1.3 MB)
     |████████████████████████████████| 1.3 MB 7.3 MB/s
Collecting gast==0.4.0
  Downloading gast-0.4.0-py3-none-any.whl (9.8 kB)
Collecting grpcio<2.0,>=1.37.0
  Downloading grpcio-1.40.0-cp37-cp37m-manylinux_2_24_aarch64.whl (39.2 MB)
     |████████████████████████████████| 39.2 MB 40 kB/s
Collecting termcolor~=1.1.0
  Downloading termcolor-1.1.0.tar.gz (3.9 kB)
Requirement already satisfied: numpy~=1.21.1 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (1.21.2)
Collecting opt-einsum~=3.3.0
  Downloading opt_einsum-3.3.0-py3-none-any.whl (65 kB)
     |████████████████████████████████| 65 kB 846 kB/s
Collecting absl-py~=0.10
  Downloading absl_py-0.13.0-py3-none-any.whl (132 kB)
     |████████████████████████████████| 132 kB 12.6 MB/s
Collecting typing-extensions~=3.7.4
  Downloading typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
Collecting google-pasta~=0.2
  Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB)
     |████████████████████████████████| 57 kB 1.3 MB/s
Collecting tensorboard~=2.6
  Downloading tensorboard-2.6.0-py3-none-any.whl (5.6 MB)
     |████████████████████████████████| 5.6 MB 10.0 MB/s
Collecting wrapt~=1.12.1
  Downloading wrapt-1.12.1.tar.gz (27 kB)
Collecting protobuf>=3.9.2
  Downloading protobuf-3.18.0-cp37-cp37m-manylinux2014_aarch64.whl (924 kB)
     |████████████████████████████████| 924 kB 10.7 MB/s
Collecting astunparse~=1.6.3
  Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Collecting cached-property
  Downloading cached_property-1.5.2-py2.py3-none-any.whl (7.6 kB)
Collecting google-auth<2,>=1.6.3
  Downloading google_auth-1.35.0-py2.py3-none-any.whl (152 kB)
     |████████████████████████████████| 152 kB 11.5 MB/s
Collecting tensorboard-data-server<0.7.0,>=0.6.0
  Downloading tensorboard_data_server-0.6.1-py3-none-any.whl (2.4 kB)
Collecting setuptools>=41.0.0
  Using cached setuptools-58.0.4-py3-none-any.whl (816 kB)
Collecting tensorboard-plugin-wit>=1.6.0
  Downloading tensorboard_plugin_wit-1.8.0-py3-none-any.whl (781 kB)
     |████████████████████████████████| 781 kB 8.2 MB/s
Collecting werkzeug>=0.11.15
  Downloading Werkzeug-2.0.1-py3-none-any.whl (288 kB)
     |████████████████████████████████| 288 kB 8.9 MB/s
Collecting google-auth-oauthlib<0.5,>=0.4.1
  Downloading google_auth_oauthlib-0.4.6-py2.py3-none-any.whl (18 kB)
Collecting requests<3,>=2.21.0
  Downloading requests-2.26.0-py2.py3-none-any.whl (62 kB)
     |████████████████████████████████| 62 kB 154 kB/s
Collecting markdown>=2.6.8
  Downloading Markdown-3.3.4-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 1.1 MB/s
Collecting pyasn1-modules>=0.2.1
  Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
     |████████████████████████████████| 155 kB 8.5 MB/s
Collecting rsa<5,>=3.1.4
  Downloading rsa-4.7.2-py3-none-any.whl (34 kB)
Collecting cachetools<5.0,>=2.0.0
  Downloading cachetools-4.2.2-py3-none-any.whl (11 kB)
Collecting requests-oauthlib>=0.7.0
  Downloading requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)
Collecting importlib-metadata
  Downloading importlib_metadata-4.8.1-py3-none-any.whl (17 kB)
Collecting pyasn1<0.5.0,>=0.4.6
  Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
     |████████████████████████████████| 77 kB 1.3 MB/s
Collecting certifi>=2017.4.17
  Downloading certifi-2021.5.30-py2.py3-none-any.whl (145 kB)
     |████████████████████████████████| 145 kB 8.2 MB/s
Collecting charset-normalizer~=2.0.0
  Downloading charset_normalizer-2.0.6-py3-none-any.whl (37 kB)
Collecting idna<4,>=2.5
  Downloading idna-3.2-py3-none-any.whl (59 kB)
     |████████████████████████████████| 59 kB 1.6 MB/s
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.6-py2.py3-none-any.whl (138 kB)
     |████████████████████████████████| 138 kB 15.9 MB/s
Collecting oauthlib>=3.0.0
  Downloading oauthlib-3.1.1-py2.py3-none-any.whl (146 kB)
     |████████████████████████████████| 146 kB 1.6 MB/s
Collecting zipp>=0.5
  Downloading zipp-3.5.0-py3-none-any.whl (5.7 kB)
Building wheels for collected packages: clang, h5py, termcolor, wrapt
  Building wheel for clang (setup.py) ... done
  Created wheel for clang: filename=clang-5.0-py3-none-any.whl size=30705 sha256=965264867ac952ffe0cdcd7e9e4ec815662a7d5e09bd44b5542bf4283fab3ac9
  Stored in directory: /home/hoto/.cache/pip/wheels/98/91/04/971b4c587cf47ae952b108949b46926f426c02832d120a082a
  Building wheel for h5py (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /home/hoto/.local/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmpjazixgh6
       cwd: /tmp/pip-install-r_317f6s/h5py_3678e278ecf34daf8f166a7050ac0992
  Complete output (69 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-aarch64-3.7
  creating build/lib.linux-aarch64-3.7/h5py
  copying h5py/__init__.py -> build/lib.linux-aarch64-3.7/h5py
  copying h5py/h5py_warnings.py -> build/lib.linux-aarch64-3.7/h5py
  copying h5py/ipy_completer.py -> build/lib.linux-aarch64-3.7/h5py
  copying h5py/version.py -> build/lib.linux-aarch64-3.7/h5py
  creating build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/__init__.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/attrs.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/base.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/compat.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/dataset.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/datatype.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/dims.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/files.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/filters.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/group.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/selections.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/selections2.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/vds.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  creating build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/__init__.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/common.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/conftest.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_attribute_create.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_attrs.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_attrs_data.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_base.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_big_endian_file.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_completions.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dataset.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dataset_getitem.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dataset_swmr.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_datatype.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dimension_scales.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dims_dimensionproxy.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dtype.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_errors.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_file.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_file2.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_file_image.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_filters.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_group.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5d_direct_chunk.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5f.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5p.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5pl.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5t.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_objects.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_selections.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_slicing.py -> build/lib.linux-aarch64-3.7/h5py/tests
  creating build/lib.linux-aarch64-3.7/h5py/tests/data_files
  copying h5py/tests/data_files/__init__.py -> build/lib.linux-aarch64-3.7/h5py/tests/data_files
  creating build/lib.linux-aarch64-3.7/h5py/tests/test_vds
  copying h5py/tests/test_vds/__init__.py -> build/lib.linux-aarch64-3.7/h5py/tests/test_vds
  copying h5py/tests/test_vds/test_highlevel_vds.py -> build/lib.linux-aarch64-3.7/h5py/tests/test_vds
  copying h5py/tests/test_vds/test_lowlevel_vds.py -> build/lib.linux-aarch64-3.7/h5py/tests/test_vds
  copying h5py/tests/test_vds/test_virtual_source.py -> build/lib.linux-aarch64-3.7/h5py/tests/test_vds
  copying h5py/tests/data_files/vlen_string_dset.h5 -> build/lib.linux-aarch64-3.7/h5py/tests/data_files
  copying h5py/tests/data_files/vlen_string_dset_utc.h5 -> build/lib.linux-aarch64-3.7/h5py/tests/data_files
  copying h5py/tests/data_files/vlen_string_s390x.h5 -> build/lib.linux-aarch64-3.7/h5py/tests/data_files
  running build_ext
  Building h5py requires pkg-config unless the HDF5 path is explicitly specified
  error: pkg-config probably not installed: FileNotFoundError(2, "No such file or directory: 'pkg-config'")
  ----------------------------------------
  ERROR: Failed building wheel for h5py
  Building wheel for termcolor (setup.py) ... done
  Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4831 sha256=49219dc8d2a0984da0c4841b0c5e83788f3a3c4f55832a1f160a0443442de651
  Stored in directory: /home/hoto/.cache/pip/wheels/3f/e3/ec/8a8336ff196023622fbcb36de0c5a5c218cbb24111d1d4c7f2
  Building wheel for wrapt (setup.py) ... done
  Created wheel for wrapt: filename=wrapt-1.12.1-cp37-cp37m-linux_aarch64.whl size=72882 sha256=7d42f58dc8673df65fb0f65475d3cc0c5d9b5465a8410228b7998e619e588a89
  Stored in directory: /home/hoto/.cache/pip/wheels/62/76/4c/aa25851149f3f6d9785f6c869387ad82b3fd37582fa8147ac6
Successfully built clang termcolor wrapt
Failed to build h5py
ERROR: Could not build wheels for h5py which use PEP 517 and cannot be installed directly

失敗・・・。
どうやらh5py関連でエラーのようなのでエラーメッセージで検索し同じ様なケースの対応をとりあえず真似してみました。

これ以降はどれが正解だったのか分からずとりあえずやった内容を列挙


setuptoolsとwheelが古いとなる情報がありpip install --upgrade setuptools wheelでアップデート
→失敗

h5pyを単体で色々なオプションで試行
pip install --no-use-pep517 h5py
→失敗
pip install --no-binary h5py
→失敗
pip install --no-binary=h5py h5py
→失敗

pkg-configをインストール
#sudo apt list --installed | grep pkg-config
→失敗

debinのパッケージにh5pyがあるようなのでインストール
#sudo apt install python3-h5py
→バージョンが2.8.0-3となんか古そう

再度TensorFlowのインストールを試行

pip install tensorflow-2.6.0-cp37-none-linux_aarch64.whl

Defaulting to user installation because normal site-packages is not writeable
Processing ./tensorflow-2.6.0-cp37-none-linux_aarch64.whl
Collecting keras-preprocessing~=1.1.2
  Using cached Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)
Collecting clang~=5.0
  Using cached clang-5.0-py3-none-any.whl
Collecting wrapt~=1.12.1
  Using cached wrapt-1.12.1-cp37-cp37m-linux_aarch64.whl
Collecting opt-einsum~=3.3.0
  Using cached opt_einsum-3.3.0-py3-none-any.whl (65 kB)
Collecting astunparse~=1.6.3
  Using cached astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Collecting tensorflow-estimator~=2.6
  Using cached tensorflow_estimator-2.6.0-py2.py3-none-any.whl (462 kB)
Collecting tensorboard~=2.6
  Using cached tensorboard-2.6.0-py3-none-any.whl (5.6 MB)
Collecting termcolor~=1.1.0
  Using cached termcolor-1.1.0-py3-none-any.whl
Collecting gast==0.4.0
  Using cached gast-0.4.0-py3-none-any.whl (9.8 kB)
Collecting flatbuffers~=1.12.0
  Using cached flatbuffers-1.12-py2.py3-none-any.whl (15 kB)
Requirement already satisfied: wheel~=0.35 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (0.37.0)
Collecting six~=1.15.0
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting keras~=2.6
  Using cached keras-2.6.0-py2.py3-none-any.whl (1.3 MB)
Collecting absl-py~=0.10
  Using cached absl_py-0.13.0-py3-none-any.whl (132 kB)
Collecting google-pasta~=0.2
  Using cached google_pasta-0.2.0-py3-none-any.whl (57 kB)
Collecting grpcio<2.0,>=1.37.0
  Using cached grpcio-1.40.0-cp37-cp37m-manylinux_2_24_aarch64.whl (39.2 MB)
Collecting protobuf>=3.9.2
  Using cached protobuf-3.18.0-cp37-cp37m-manylinux2014_aarch64.whl (924 kB)
Collecting h5py~=3.1.0
  Using cached h5py-3.1.0.tar.gz (371 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Collecting typing-extensions~=3.7.4
  Using cached typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
Requirement already satisfied: numpy~=1.21.1 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (1.21.2)
Collecting cached-property
  Using cached cached_property-1.5.2-py2.py3-none-any.whl (7.6 kB)
Requirement already satisfied: setuptools>=41.0.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorboard~=2.6->tensorflow==2.6.0) (58.0.4)
Collecting google-auth<2,>=1.6.3
  Using cached google_auth-1.35.0-py2.py3-none-any.whl (152 kB)
Collecting requests<3,>=2.21.0
  Using cached requests-2.26.0-py2.py3-none-any.whl (62 kB)
Collecting google-auth-oauthlib<0.5,>=0.4.1
  Using cached google_auth_oauthlib-0.4.6-py2.py3-none-any.whl (18 kB)
Collecting werkzeug>=0.11.15
  Using cached Werkzeug-2.0.1-py3-none-any.whl (288 kB)
Collecting tensorboard-data-server<0.7.0,>=0.6.0
  Using cached tensorboard_data_server-0.6.1-py3-none-any.whl (2.4 kB)
Collecting markdown>=2.6.8
  Using cached Markdown-3.3.4-py3-none-any.whl (97 kB)
Collecting tensorboard-plugin-wit>=1.6.0
  Using cached tensorboard_plugin_wit-1.8.0-py3-none-any.whl (781 kB)
Collecting cachetools<5.0,>=2.0.0
  Using cached cachetools-4.2.2-py3-none-any.whl (11 kB)
Collecting rsa<5,>=3.1.4
  Using cached rsa-4.7.2-py3-none-any.whl (34 kB)
Collecting pyasn1-modules>=0.2.1
  Using cached pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
Collecting requests-oauthlib>=0.7.0
  Using cached requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)
Collecting importlib-metadata
  Using cached importlib_metadata-4.8.1-py3-none-any.whl (17 kB)
Collecting pyasn1<0.5.0,>=0.4.6
  Using cached pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
Collecting urllib3<1.27,>=1.21.1
  Using cached urllib3-1.26.6-py2.py3-none-any.whl (138 kB)
Collecting charset-normalizer~=2.0.0
  Using cached charset_normalizer-2.0.6-py3-none-any.whl (37 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.2-py3-none-any.whl (59 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2021.5.30-py2.py3-none-any.whl (145 kB)
Collecting oauthlib>=3.0.0
  Using cached oauthlib-3.1.1-py2.py3-none-any.whl (146 kB)
Collecting zipp>=0.5
  Using cached zipp-3.5.0-py3-none-any.whl (5.7 kB)
Building wheels for collected packages: h5py
  Building wheel for h5py (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /home/hoto/.local/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmpqu4eq5l4
       cwd: /tmp/pip-install-r22datm0/h5py_c83ebf6719484a6cb76ecd27971abef2
  Complete output (70 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-aarch64-3.7
  creating build/lib.linux-aarch64-3.7/h5py
  copying h5py/__init__.py -> build/lib.linux-aarch64-3.7/h5py
  copying h5py/h5py_warnings.py -> build/lib.linux-aarch64-3.7/h5py
  copying h5py/ipy_completer.py -> build/lib.linux-aarch64-3.7/h5py
  copying h5py/version.py -> build/lib.linux-aarch64-3.7/h5py
  creating build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/__init__.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/attrs.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/base.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/compat.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/dataset.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/datatype.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/dims.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/files.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/filters.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/group.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/selections.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/selections2.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  copying h5py/_hl/vds.py -> build/lib.linux-aarch64-3.7/h5py/_hl
  creating build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/__init__.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/common.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/conftest.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_attribute_create.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_attrs.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_attrs_data.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_base.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_big_endian_file.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_completions.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dataset.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dataset_getitem.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dataset_swmr.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_datatype.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dimension_scales.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dims_dimensionproxy.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_dtype.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_errors.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_file.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_file2.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_file_image.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_filters.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_group.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5d_direct_chunk.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5f.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5p.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5pl.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_h5t.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_objects.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_selections.py -> build/lib.linux-aarch64-3.7/h5py/tests
  copying h5py/tests/test_slicing.py -> build/lib.linux-aarch64-3.7/h5py/tests
  creating build/lib.linux-aarch64-3.7/h5py/tests/data_files
  copying h5py/tests/data_files/__init__.py -> build/lib.linux-aarch64-3.7/h5py/tests/data_files
  creating build/lib.linux-aarch64-3.7/h5py/tests/test_vds
  copying h5py/tests/test_vds/__init__.py -> build/lib.linux-aarch64-3.7/h5py/tests/test_vds
  copying h5py/tests/test_vds/test_highlevel_vds.py -> build/lib.linux-aarch64-3.7/h5py/tests/test_vds
  copying h5py/tests/test_vds/test_lowlevel_vds.py -> build/lib.linux-aarch64-3.7/h5py/tests/test_vds
  copying h5py/tests/test_vds/test_virtual_source.py -> build/lib.linux-aarch64-3.7/h5py/tests/test_vds
  copying h5py/tests/data_files/vlen_string_dset.h5 -> build/lib.linux-aarch64-3.7/h5py/tests/data_files
  copying h5py/tests/data_files/vlen_string_dset_utc.h5 -> build/lib.linux-aarch64-3.7/h5py/tests/data_files
  copying h5py/tests/data_files/vlen_string_s390x.h5 -> build/lib.linux-aarch64-3.7/h5py/tests/data_files
  running build_ext
  Loading library to get version: libhdf5.so
  error: Unable to load dependency HDF5, make sure HDF5 is installed properly
  error: libhdf5.so: cannot open shared object file: No such file or directory
  ----------------------------------------
  ERROR: Failed building wheel for h5py
Failed to build h5py
ERROR: Could not build wheels for h5py which use PEP 517 and cannot be installed directly

失敗・・・でもエラーメッセージが変わっているようで今度はlibhdf5関連

似た事象をインターネットで調べてversioned-hdf5をインストールしてみたけれど失敗・・・。

よくxx.soファイルがないのはコンパイルに必要なライブラリがない場合がおおいのでdebianパッケージのlibhdf5-devをインストールしてみる

#sudo apt install libhdf5-dev

TensorFlowのインストールを試行

pip install tensorflow-2.6.0-cp37-none-linux_aarch64.whl
Defaulting to user installation because normal site-packages is not writeable
Processing ./tensorflow-2.6.0-cp37-none-linux_aarch64.whl
Requirement already satisfied: six~=1.15.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (1.15.0)
Requirement already satisfied: grpcio<2.0,>=1.37.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (1.40.0)
Requirement already satisfied: protobuf>=3.9.2 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (3.18.0)
Requirement already satisfied: clang~=5.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (5.0)
Requirement already satisfied: keras~=2.6 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (2.6.0)
Requirement already satisfied: google-pasta~=0.2 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (0.2.0)
Requirement already satisfied: h5py~=3.1.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (3.1.0)
Requirement already satisfied: numpy~=1.21.1 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (1.21.2)
Requirement already satisfied: gast==0.4.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (0.4.0)
Requirement already satisfied: keras-preprocessing~=1.1.2 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (1.1.2)
Requirement already satisfied: wrapt~=1.12.1 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (1.12.1)
Requirement already satisfied: absl-py~=0.10 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (0.13.0)
Requirement already satisfied: opt-einsum~=3.3.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (3.3.0)
Requirement already satisfied: tensorflow-estimator~=2.6 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (2.6.0)
Requirement already satisfied: wheel~=0.35 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (0.37.0)
Requirement already satisfied: astunparse~=1.6.3 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (1.6.3)
Requirement already satisfied: flatbuffers~=1.12.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (1.12)
Requirement already satisfied: termcolor~=1.1.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (1.1.0)
Requirement already satisfied: typing-extensions~=3.7.4 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (3.7.4.3)
Requirement already satisfied: tensorboard~=2.6 in /home/hoto/.local/lib/python3.7/site-packages (from tensorflow==2.6.0) (2.6.0)
Requirement already satisfied: cached-property in /home/hoto/.local/lib/python3.7/site-packages (from h5py~=3.1.0->tensorflow==2.6.0) (1.5.2)
Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorboard~=2.6->tensorflow==2.6.0) (0.6.1)
Requirement already satisfied: setuptools>=41.0.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorboard~=2.6->tensorflow==2.6.0) (58.0.4)
Requirement already satisfied: requests<3,>=2.21.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorboard~=2.6->tensorflow==2.6.0) (2.26.0)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /home/hoto/.local/lib/python3.7/site-packages (from tensorboard~=2.6->tensorflow==2.6.0) (0.4.6)
Requirement already satisfied: werkzeug>=0.11.15 in /home/hoto/.local/lib/python3.7/site-packages (from tensorboard~=2.6->tensorflow==2.6.0) (2.0.1)
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /home/hoto/.local/lib/python3.7/site-packages (from tensorboard~=2.6->tensorflow==2.6.0) (1.8.0)
Requirement already satisfied: markdown>=2.6.8 in /home/hoto/.local/lib/python3.7/site-packages (from tensorboard~=2.6->tensorflow==2.6.0) (3.3.4)
Requirement already satisfied: google-auth<2,>=1.6.3 in /home/hoto/.local/lib/python3.7/site-packages (from tensorboard~=2.6->tensorflow==2.6.0) (1.35.0)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in /home/hoto/.local/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard~=2.6->tensorflow==2.6.0) (4.2.2)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /home/hoto/.local/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard~=2.6->tensorflow==2.6.0) (0.2.8)
Requirement already satisfied: rsa<5,>=3.1.4 in /home/hoto/.local/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard~=2.6->tensorflow==2.6.0) (4.7.2)
Requirement already satisfied: requests-oauthlib>=0.7.0 in /home/hoto/.local/lib/python3.7/site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard~=2.6->tensorflow==2.6.0) (1.3.0)
Requirement already satisfied: importlib-metadata in /home/hoto/.local/lib/python3.7/site-packages (from markdown>=2.6.8->tensorboard~=2.6->tensorflow==2.6.0) (4.8.1)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /home/hoto/.local/lib/python3.7/site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard~=2.6->tensorflow==2.6.0) (0.4.8)
Requirement already satisfied: certifi>=2017.4.17 in /home/hoto/.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard~=2.6->tensorflow==2.6.0) (2021.5.30)
Requirement already satisfied: idna<4,>=2.5 in /home/hoto/.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard~=2.6->tensorflow==2.6.0) (3.2)
Requirement already satisfied: charset-normalizer~=2.0.0 in /home/hoto/.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard~=2.6->tensorflow==2.6.0) (2.0.6)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/hoto/.local/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard~=2.6->tensorflow==2.6.0) (1.26.6)
Requirement already satisfied: oauthlib>=3.0.0 in /home/hoto/.local/lib/python3.7/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard~=2.6->tensorflow==2.6.0) (3.1.1)
Requirement already satisfied: zipp>=0.5 in /home/hoto/.local/lib/python3.7/site-packages (from importlib-metadata->markdown>=2.6.8->tensorboard~=2.6->tensorflow==2.6.0) (3.5.0)
Installing collected packages: tensorflow
Successfully installed tensorflow-2.6.0

無事インストール成功!!

■kerasのインストール


pip install keras

Defaulting to user installation because normal site-packages is not writeable
Collecting keras
  Using cached keras-2.6.0-py2.py3-none-any.whl (1.3 MB)
Installing collected packages: keras
Successfully installed keras-2.6.0

すんなりインストール完了

とりあえずインストールは完了したけれど本当に使用できるか試してみないと。

【追記】

kerasを調べていてITmediaの記事を読んでやっと理解、kerasはtensorflow.kerasとしてTensorFlow2にで組み込まれたようです。なのでわざわざkerasをインストールする必要はなかったようです。







2021年9月17日金曜日

【scikit-learn】Linux(ベータ版)にpandasとscikit-learnのインストール

 numpyまではインストールしていましたが参考書を読み進みそろそろ機械学習のライブラリをしようすることになりそうなのでpandasとscikit-learnをインストールしました。

intel系のマシンならあまり心配ではないのですが使用しているChromeBook(Detachable CM3)で使用されているCPUはARM系なのでこういう計算系のライブラリのインストールが心配でした。

ただ、結果からいうととくに問題なくインストール完了です。


pipのupgradeしろと警告メッセージが表示していますがpandasとしては1.3.3がインストールされました。


scikit-learnも1.20.3が問題なくインストール完了

これで安心して勉強できます。

2021年8月9日月曜日

Linux(ベータ版)にpipとScipyのインストール

 数理最適化(scipy.optimize)をする必要があり数値解析パッケージ(Scipy)をインストールすることに。

参考にしたサイトではpipコマンドを使用しており今後のことも考えてまずはpipをインストール


Chormebook上のLinux(ベータ版)のPythonはpython3なのについ癖でpythonと入力としてしまいます。

scipy(1.7.1)が問題なくインストールされました。

2021年7月25日日曜日

Visual Studio CodeのJupyterでExpected expression Pylanceエラー

 Visual Studio CodeのJupyter上でmatplotlibを使用していたら突然動かなくなりました。

下部のエラー画面に”Expected expression Pylance”エラーが表示されていることに気がつき該当のエラー行を見てみるとmatplotlib のインタラクティブサポートを有効化するためのコマンドの行がエラーとのこと

%matplotlib inline ←該当のエラー行

今まで問題なく動作していたのに・・・Visual Studio Codeを再起動してみても改善せず原因不明。

ただ、作業中に拡張モジュールをバージョンアップをしたような・・・。

試しにエラー行をコメントアウトしてみるとエラーはなくなりました、グラフが表示しなくなると思いきや問題なく表示します。

もしかして不要になったのかな。

■発生したバージョン

Visual Studio Code:1.58.2

Jupyter:v2021.8.1054968649

Pylance:v2021.7.5

Python:v2021.7.1060902895

2021年5月26日水曜日

matplotlibで日本語表示のためにIPAフォントをインストール

 Linux(ベータ版)を日本語化する際にデフォルトでNoto Sans CJK JP日本語フォントがインストールされていいたので日本語フォントは追加していませんでした。

しかし、パッケージでインストールしたmatplotlibはVer3.0.2のようでttcファイルに未対応(V3r3.1から対応したらしい)のようなので上記の日本語フォントが扱えないらしい。

Noto Sans CJK JPはttcファイル

仕方なくIPAフォントをインストールすることにしました。

■IPAフォントパッケージインストール

>sudo apt install fonts-ipaexfont

■インストールされたフォントの確認

 >fc-list | grep 'IPA'

(実行結果)
/usr/share/fonts/opentype/ipaexfont-gothic/ipaexg.ttf: IPAexゴシック,IPAexGothic:style=Regular
/usr/share/fonts/opentype/ipaexfont-mincho/ipaexm.ttf: IPAex明朝,IPAexMincho:style=Regular
/usr/share/fonts/truetype/fonts-japanese-mincho.ttf: IPAex明朝,IPAexMincho:style=Regular
/usr/share/fonts/truetype/fonts-japanese-gothic.ttf: IPAexゴシック,IPAexGothic:style=Regular

ttfファイルがインストールされました。

■Jypyter Notebookでのテストコード

import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['font.family'] = 'sans-serif'
rcParams['font.sans-serif']  = ['IPAexGothic']
x = [1,2,3,4,5]
y=[2,4,6,8,10]
plt.plot(x,y)
plt.title('日本語タイトル')
plt.show()

無事日本語タイトルが表示できました。

2020年7月5日日曜日

tkinterでclass化

tkinterをClass化した際の備忘録

■独自クラス

import tkinter as tk
import tkinter.messagebox

class Application(tk.Frame):
    def __init__(self):
        master = tk.Tk() # ウィジェットを作成
        super().__init__(master)
        self.pack()
        master.geometry("300x300")  # ウインドウサイズ
        master.title("tkinter")    # ウインドウタイトル
        btn_message = tk.Button(self, text = "Python/Tkinter", command=self.func_btn_click ) # ボタンオブジェクト作成
        btn_message.pack()   # ボタンオブジェクトを配置
        btn_exit = tk.Button(self, text = "exit", command=self.func_btn_exit ) # exitボタンオブジェクト作成
        btn_exit.pack() # ボタンオブジェクトを配置
    # メッセージボタンクリック時に呼び出されるメソッド
    def func_btn_click(self):
        tk.messagebox.showinfo("title", "message")
    # exitボタンクリック時に呼び出されるメソッド
    def func_btn_exit(self):
#         self.master.destroy() # widgetを破棄することで終了させる、今回はquitで終了
        self.quit()

if __name__ == "__main__":
    app = Application() # Applicationのインスタンス化
    app.mainloop() # tk上のイベントを補足しイベントに対応した処理を実行する

■独自クラスからインスタンスを作成事項する実行モジュール

import tkinter_class

if __name__ == "__main__":
    app = tkinter_class.Application() # Applicationのインスタンス化
    app.mainloop() # tk上のイベントを補足しイベントに対応した処理を実行する

2020年6月17日水曜日

Windowsでcurses

コマンドプロンプトで動作するコンソールアプリケーションを作成してみようとした時の備忘録

(環境)
  • Windows7(64bit)
  • OracleClient11.2.0.4(32bit)
  • Python3.6.1(32bit)

  1. Windows版のPythonにはcursesライブラリが標準インストールされていない、windows-cursesやunicurses等の代替えライブラリのインストールが必要
  2. キーボード入力のマルチバイト文字列はgetstr()で取得可能、マルチバイト文字ならget_wch()
  3. curses.textpad.Textboxはマルチバイト文字に対応していない(入力しても表示もせず、取得も出来ない)
  4. refresh()後にaddstr()でマルチバイトを表示させようとすると途中の文字列までしか表示しない、回避策として別ウィンドウオブジェクトを作成し文字列入力をさせる
  5. getstr()後にaddstr()でマルチバイトを表示させようとすると途中の文字列までしか表示しない
  6. getstr()で入力中も文字を表示させる際はcurses.echo()でエコーモードにする
途中

2020年2月22日土曜日

Python for Win32 Extensions(Pywin32)でイベントログ(Eventlog)アクセス

イベントログを取得する用件がありPythonで処理してみることに。

WEBで検索してみると意外に容易にできそうな感じでPython for Win32 Extensions(Pywin32)のwin32evtlogモジュールのReadEventLogメソッドを使用。ただ思ったほど情報は多くないけれどサンプルソースからなんとか。。。

ReadEventLogメソッドの戻り値(PyEventLogRecordオブジェクト)のプロパティからイベントビューアーにあるレベルに該当するものを探してみると同じ名前のものはなくそれらしいのはEventTypeぐらい。

ただ、調べてみると値が微妙に違う・・・

EventTypeイベントビューアーのレベルEVENTCREATEコマンドの種類(/T)
0:成功情報 Level:0SUCCESS
1:エラーエラー Level:2ERROR
2:警告警告 Level:3WARNING
4:情報情報 Level:4INFORMATION

win32evtlogの定数をDIR関数で調べてみるとEventTypeに使えそうなものが以下の様な感じかも。


  • EVENTLOG_ERROR_TYPE : 1
  • EVENTLOG_WARNING_TYPE : 2
  • EVENTLOG_INFORMATION_TYPE : 4
  • EVENTLOG_AUDIT_SUCCESS : 8
  • EVENTLOG_AUDIT_FAILURE : 16
ついでに気になったこと(上手く実装できなかった箇所)
  • win32evtlogutil.SafeFormatMessageでイベントビューアーに表示しているメッセージを取得できないイベントが存在した。
  • イベントビューアーに表示しているイベントID(EventId)とは異なっていた。



2019年10月22日火曜日

JupyterLab(JupyterNotebook)のインストール

macOS Mojave(10.14.6)にJupyterLab(JupyterNoteBook後継版)のインストールメモ、既にPython3.7.1をインストールしている状態でAnaconda(データサイエンス向けのPythonパッケージなどを提供するプラットフォーム)を使用せずJupyterLabを単体でインストールすることに。

1.jupyterlabインストール


>pip install jupyterlab

インストールしていたpipのバージョンが古いとのメッセージ

You are using pip version 10.0.1, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

なので先にpipをアップグレード

>pip install --upgrade pip

Collecting pip
  Downloading https://files.pythonhosted.org/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 6.5MB/s 
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-19.3.1

再度jupyterlabをインストールしてとりあえずエラーなく完了、またJuypyterLabでグラフも表示させたいのでついでにmatplotlibもインストール

>pip install matplotlib

2.準備


作業ディレクトリを変更したく毎回起動オプションに設定するのが面倒なので作業用フォルダの作成と設定ファイルを作成し必要な設定をする

・作業ディレクトリ作成(ホームディレクトリ内作成)
mkdir ~/jupyterlab

・設定ファイルの作成

>jupyter notebook --generate-config

~/.jupyterフォルダ内にjupyter_notebook_config.pyが作成されるので先の下記の箇所を有効(コメント解除)にして作業フォルダを指定
c.NotebookApp.notebook_dir = '[任意フォルダ]'

3.実行


>jupyter lab

デフォルトは自動的にブラウザも起動する



  • jupyterlabはIE11がサポートされていないためWindowsだと画面はなにも表示しない、Notebookは使用できるのでその場合は「http://localhost:8888/tree」にアクセスする(初回は/?token=・・・が必要かも)
  • 手動でURLを指定する場合は「http://localhost:8888/lab」
  • ターミナルを閉じてもバックグラウンド起動させておく場合は「>nohup jupyter lab &」で実行
  • 手動実行時のURLに認証用トークンを指定する必要がある場合はターミナル画面にURL(http://localhost:8888/?token=d6d62e9f50ee4668e355409590ada3a34ce70658ead9aaf8)が表示されているので「/?token」以降を入力する


4.グラフの表示確認


(テストプログラム)

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10,100)
y = np.sin(x)
plt.plot(x,y)




5.Tips


(1)設定ファイル
・起動時に自動的にブラウザ起動させない場合
c.NotebookApp.open_browser = False
・別のPCからアクセスさせる場合
c.NotebookApp.ip = '*'
・ポート番号を変更(8801)する場合
c.NotebookApp.port = 8801
・認証用のトークンをなくす場合
c.NotebookApp.toekn = ''
・rootユーザでの実行を許容する場合(Macでは個人IDでログインしていたので不要)
c.NotebookApp.allow_root = True

(2)起動オプション
・help(MacではLinuxの場合ほどオプションが表示しない)
--help or --help-all
・リモートアクセス許可
--ip=0.0.0.0
・起動時に自動的にブラウザ起動させない
--no-browser
rootユーザでの実行を許容
--allow-root



2019年4月26日金曜日

ConfigParserでUnicodeDecodeError

Windows7環境のPython3でConfigParserを使用したら以下のエラーメッセージ

UnicodeDecodeError: 'cp932' codec can't decode byte 0x86 in position 21: illegal multibyte sequence

読み込みファイル(config.ini)にマルチバイトを含めたとたん・・・。

まぁメッセージ的に文字コードの問題となので検索して

普段なら

import configparser

config = configparser.ConfigParser()
config.read('config.ini')



import configparser
import codecs 
config = configparser.ConfigParser()
config.readfp(codecs.open("config.ini", "r", "utf8"))

にして回避

2019年1月3日木曜日

macOS Mojave 10.14.2にPython3.7.1インストール



前回、Homebrewをインストールしたのでやっとpythonをインストール


  • macOS Mojave 10.14.2
  • Python3.7.1

・pyenvのインストール

今のところ複数のバージョンを切り替えて使う予定がないのでpyenvのインストールは不要あったかもしれないけれど今後のために。

(インストールコマンド)
$brew install pyenv

(インストールログ)
brew install pyenv
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
atomist-cli                               jmxterm                                   ruby@2.5
==> Updated Formulae
algernon                       dub                            libcds                         re2
ballerina                      dvm                            libhttpserver                  roswell
bullet                         easyengine                     libjwt                         swi-prolog
checkstyle                     efl                            librealsense                   swiftformat
clojure                        fbi-servefiles                 meson                          syncthing
cointop                        gexiv2                         mono                           tika
dartsim                        global                         neovim                         topgrade
dcd                            gobject-introspection          nnn                            unnethack
dependency-check               grakn                          node-build                     verilator
dfmt                           groovy                         pagmo                          wtf
diamond                        http-parser                    pgbadger                       ydcv
diffutils                      imagemagick                    php-cs-fixer                   youtube-dl
docker-machine-parallels       kops                           picard-tools
dscanner                       ldc                            plantuml
==> Deleted Formulae
pyexiv2

==> Installing dependencies for pyenv: autoconf, openssl, pkg-config and readline
==> Installing pyenv dependency: autoconf
==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.mojave.bottle.4.tar.gz
######################################################################## 100.0%
==> Pouring autoconf-2.69.mojave.bottle.4.tar.gz
==> Caveats
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/autoconf
==> Summary
瑳  /usr/local/Cellar/autoconf/2.69: 71 files, 3.0MB
==> Installing pyenv dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2q.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2q.mojave.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ‾/.bash_profile

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

==> Summary
瑳  /usr/local/Cellar/openssl/1.0.2q: 1,794 files, 12.1MB
==> Installing pyenv dependency: pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.29.2.mojave.bottle.tar.gz
瑳  /usr/local/Cellar/pkg-config/0.29.2: 11 files, 627.2KB
==> Installing pyenv dependency: readline
==> Downloading https://homebrew.bintray.com/bottles/readline-7.0.5.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring readline-7.0.5.mojave.bottle.tar.gz
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

==> Summary
瑳  /usr/local/Cellar/readline/7.0.5: 46 files, 1.5MB
==> Installing pyenv
==> Downloading https://homebrew.bintray.com/bottles/pyenv-1.2.8_1.mojave.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring pyenv-1.2.8_1.mojave.bottle.1.tar.gz
瑳  /usr/local/Cellar/pyenv/1.2.8_1: 612 files, 2.4MB
==> Caveats
==> autoconf
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/autoconf
==> openssl
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ‾/.bash_profile

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

For pkg-config to find openssl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

==> readline
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"


(パス追加)
pyenvのパスを通すために.bash_profileに追加
※自分の環境には.bash_profileは存在しておらず今回新規に作成

・.bash_profile作成
$touch ~/.bash_profile

・パス追加
.bash_profileに以下を追加
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

・.bash_profileの読み込み
パスに追加しても次回のシェル起動時からしか有効にならないので手動で.bash_profileを読み込ませる

$ source ~/.bash_profile

・pythonのインストール


pyenvでインストール出来るバージョンを確認する

$ pyenv install --list

anacondaやjpythonなども表示するけれど数字だけのがpythonのことのようで、今回は現時点で最新の3.7.1をインストールすることに

$ pyenv install 3.7.1

(インストールログ)
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.1.tar.xz...
-> https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
Installing Python-3.7.1...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.14.2 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/18/0w69zlln2v54_mhnf6s014dc0000gn/T/python-build.20190103125847.9526
Results logged to /var/folders/18/0w69zlln2v54_mhnf6s014dc0000gn/T/python-build.20190103125847.9526.log

Last 10 log lines:
rm -f ./pybuilddir.txt ; \
exit 1 ; \
fi
Fatal Python error: init_sys_streams: can't initialize sys standard streams
LookupError: unknown encoding: SJIS

Current thread 0x000000011701a5c0 (most recent call first):
/bin/sh: line 1: 18246 Abort trap: 6           ./python.exe -E -S -m sysconfig --generate-posix-vars
generate-posix-vars failed
make: *** [pybuilddir.txt] Error 1

うーん、とりあえずエンコーディングのSJISを知らないと・・・ターミナルのテキストエンコーディングをUTF-8にしてリトライ
※そもそも~(チルダ)を入力できず問題でエンコーディングをUTF-8に変更はしていたけれどターミナルを開きなおしていなかったのでシェルとしてはSJISのままだった。

(インストールログ)
pyenv install 3.7.1
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.1.tar.xz...
-> https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
Installing Python-3.7.1...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.14.2 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/18/0w69zlln2v54_mhnf6s014dc0000gn/T/python-build.20190103130926.18567
Results logged to /var/folders/18/0w69zlln2v54_mhnf6s014dc0000gn/T/python-build.20190103130926.18567.log

Last 10 log lines:
  File "/private/var/folders/18/0w69zlln2v54_mhnf6s014dc0000gn/T/python-build.20190103130926.18567/Python-3.7.1/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/private/var/folders/18/0w69zlln2v54_mhnf6s014dc0000gn/T/python-build.20190103130926.18567/Python-3.7.1/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/18/0w69zlln2v54_mhnf6s014dc0000gn/T/python-build.20190103130926.18567/Python-3.7.1/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/private/var/folders/18/0w69zlln2v54_mhnf6s014dc0000gn/T/python-build.20190103130926.18567/Python-3.7.1/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip._internal
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

調べてみるとMojave用のmacOS SDK headerがインストールされていないかららしく手動でインストールしてみることに

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

(インストールログ)
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Password:
installer: Package name is macOS_SDK_headers_for_macOS_10.14
installer: Installing at base path /

installer: The install was successful.

再度python3.7.1をインストールして無事成功
(インストールログ)
$ pyenv install 3.7.1
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.1.tar.xz...
-> https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
Installing Python-3.7.1...
python-build: use readline from homebrew

Installed Python-3.7.1 to /Users/[ユーザid hogehoge]/.pyenv/versions/3.7.1

・pythonバージョンの切り替え

インストールしただけではデフォルトのpythonはもともとインストールされているバージョンが使用されるので切り替える

$ python --version
Python 2.7.10
$ pyenv global 3.7.1
$ pyenv versions
  system

* 3.7.1 (set by /Users/[ユーザid hogehoge]/.pyenv/version)
$ python --version
Python 3.7.1

※選ばれているバージョンの前に*が表示しているっぽい

ちなみにアンインストール時は
$ pyenv uninstall 3.7.1

参考サイト