ImportError: cannot import name 'abs'

It seems to be a problem if there is a previous installation of tensorflow available. These steps seems to solve the problem.

1) uninstalling tensorflow 2) uninstalling protobuf 3) reinstalling tensorflow (which should come along with the correct protobuf version.

Also need to go to

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Lib\site-packages

and delete all tensorflow related folders

Source : https://github.com/tensorflow/tensorflow/issues/20778


  • Edit:

Create a virtual env and install TF-GPU, Its faster and safer.

  • Original Answer:

OS : Ubuntu 18.04.1

Python Version 3.6

Solution :

Uninstalled tensorflow 1.10

python3 -m pip uninstall tensorflow

Re-installed it again

python3 -m pip install tensorflow==1.8.0

This issue is created cause of older versions of tensorflow dependencies like protobuff and others which gets installed during tensorflow installation, So if you wanna use tensorflow 1.10 you have to uninstall rest of the dependencies or upgrade them.

In case you want to install 1.10.1 then you have to remove these packages

absl-py
astor
gast 
grpcio 
markdown 
numpy 
protobuf 
setuptools 
six 
tensorboard 
tensorflow 
termcolor 
werkzeug 
wheel
protobuf

then do sudo python3 -m pip uninstall tensorflow In case a tensorflow is installed in root user then install it using python3 -m pip install tensorflow --user --no-cache

IF you still face this problem then repeat all the steps above and do find ~/ -name tensorflow and delete every folder that pops up and retry installation.


Suggested solution on the following link worked for me

https://github.com/tensorflow/tensorflow/issues/20778#issuecomment-410962482

The full solution to this issue is to clean up all TF installation files from your system. Here is how to do that. Run the following first:

$ pyhthon
> import tensorflow as tf
> tf.__file__
'path/to/your/python/installation/site-packages/tensorflow/__init__.pyc'

From the above command, you need to go and remove the folder

path/to/your/python/installation/site-packages/tensorflow

Finally, you need to run

$ pip uninstall tensorflow # Also add -gpu if you installed the GPU version
$ pip install tensorflow # Also add -gpu if you installed the GPU version

Then it should work.

This worked for me in ubuntu 18.0.4

pip uninstall tensorflow protobuf --yes
find $CONDA_PREFIX -name "tensorflow" | xargs -Ipkg rm -rfv pkg
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0-cp36-cp36m-linux_x86_64.whl --no-cache-dir

Solution found from GitHub: ImportError: cannot import name 'abs' #20778.