TensorFlow
fails to import
Problem
You have TensorFlow
installed on your cluster.
When you try to import TensorFlow
, it fails with an Invalid Syntax
or import
error.
Cause
The version of protobuf
installed on your cluster is not compatible with your version of TensorFlow
.
Solution
Use a cluster-scoped init script to install TensorFlow
with matching versions of NumPy
and protobuf
.
Create the init script.
dbutils.fs.put("/databricks/<init-script-folder>/install-tensorflow.sh",""" #!/bin/bash set -e /databricks/python/bin/python -V /databricks/python/bin/pip install tensorflow protobuf==3.17.3 numpy==1.15.0 """, True)
Install the init script that you just created as a cluster-scoped init script.
You will need the full path to the location of the script (
dbfs:/databricks/<init-script-folder>/install-tensorflow.sh
).Restart the cluster after you have installed the init script.
Note
Uninstall all existing versions of NumPy
before installing the init script on your cluster.