操作系统版本 ubuntu18.0.4
机器树莓派4B

目标安装 tensorflow

先看下面连接文章,下载到你需要的tensorflow

树莓派4B安装Tensorflow(Python3.5和3.7下分别进行安装)

下载的版本需要和你的机器操作系统python版本 三者对应

在安装tensorflow之前,需要安装一些工具,再安装一些依赖库

首先安装

sudo apt-get install libhdf5-dev

然后安装cython(不是cpython)

sudo pip install Cython

准备工作已经做好

接下来可以直接
sudo pip install tensorflow-2.2.0-cp37-none-linux_aarch64.whl

pip会自动解决tensorflow的依赖库,但是其中scipy和h5py会比较缓慢

keras-preprocessing, gast, absl-py, grpcio, h5py, opt-einsum, tensorflow-estimator, termcolor, protobuf, tensorboard-plugin-wit, wheel, pyasn1, rsa, cachetools, pyasn1-modules, google-auth, oauthlib, requests-oauthlib, google-auth-oauthlib, zipp, importlib-metadata, markdown, werkzeug, tensorboard, wrapt, astunparse, google-pasta, tensorflow

这些是sudo pip install tensorflow-2.2.0-cp37-none-linux_aarch64.whl命令运行的时候检查并安装的依赖库
如果安装的时候卡住,退出手动安装一下

sudo pip install xxxx

安装完成后

运行下面代码

import tensorflow as tfprint(tf.__version__)mnist = tf.keras.datasets.mnist(x_train, y_train),(x_test, y_test) = mnist.load_data()x_train, x_test = x_train / 255.0, x_test / 255.0model = tf.keras.models.Sequential([  tf.keras.layers.Flatten(input_shape=(28, 28)),  tf.keras.layers.Dense(128, activation='relu'),  tf.keras.layers.Dropout(0.2),  tf.keras.layers.Dense(10, activation='softmax')])model.compile(optimizer='adam',              loss='sparse_categorical_crossentropy',              metrics=['accuracy'])model.fit(x_train, y_train, epochs=5)model.evaluate(x_test, y_test)

如果输出正常,说明tensorflow基本功能已经ok