确保python3环境,以下安装环境是python3.8。

1.安装BLAS库,用于快速张量运算

sudo apt-get install build-essential cmake git unzip \

pkg-config libopenblas-dev liblapack-dev

若报错:没有可用的软件包cmake,但是它被其他的软件包。。。。。

则输入:sudo apt-get update,等待更新完成后再运行上述命令一遍

2.安装SciPy

sudo apt-get install python3-scipy python3-yaml

3.安装HDF5,将Keras模型高效存取

sudo apt-get install libhdf5-serial-dev python3-h5py

4.安装Graphviz和pydot-ng,用于Keras模块可视化

sudo apt-get install graphviz

sudo pip3 install pydot-ng

5.安装某些代码示例中用到的其他包

sudo apt-get install python-opencv

6.安装TensorFlow

不支持GPU的安装命令如下:

sudo pip3 install tensorflow

下载慢建议用豆瓣的tensorflow镜像

python3 -m pip install tensorflow -i https://pypi.douban.com/simple

如果报错,就执行

pip3 install --upgrade pip

7.安装Theano

sudo pip3 install theano

如果安装过程中出现和我一样的错误,重新运行一次命令就行

8.安装Keras

sudo pip3 install keras

9.测试

python3

import tensorflow

import keras

没报错就说明OK。

注意:若tensorflow与keras、numpy的版本必须对应否则会报错。所以安装时要指定版本号。

!pip3 uninstall keras-nightly

!pip3 uninstall -y tensorflow

!pip3 install keras==2.1.6

!pip3 install tensorflow==1.15.0(1.14.0也行)

!pip3 install h5py==2.10.0

!pip3 install numpy==1.15.0

10.参考文献

[1]https://stackoverflow.com/questions/67694895/module-tensorflow-api-v1-compat-v2-has-no-attribute-internal-google-col

[2]https://blog.csdn.net/cufe_shang/article/details/100338443