tensorflow: ImportError: cannot import name 'abs'

Windows 10 , CUDA 9 + CUDNN 7, Python3.6(Anaconda5.2) install the TensorFlow 1.9: pip install --upgrade tensorflow-gpu when I import the TensorFlow in ipyhon: from tensorflow.python.keras._impl.keras.backend import abs ImportError: cannot import name 'abs' image

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 66
  • Comments: 46 (15 by maintainers)

Most upvoted comments

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks. Have I written custom code OS Platform and Distribution TensorFlow installed from TensorFlow version Bazel version CUDA/cuDNN version GPU model and memory Exact command to reproduce

This issue seems to suggest a fix… https://github.com/tensorflow/probability/issues/46

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

Not sure if these issues have same root cause, but maybe something to try before a patch release

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.

You are exactly right! On my personal machine, even when I did “pip uninstall tensorflow” it did not fix things. I had to go into my site-packages directory, and delete all “tensorflow” directory manually and then reinstall. Then it just worked.

So, Id say this is a pip bug. the workaround is to purge all TF files your python distribution has. then reinstall TF.

I’ve dealt with this problem (in conda env on Ubuntu 18.04):

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

All the solutions above have been tried and none of them worked , I just downgraded to tensorflow 1.8.0 and the problem is solved…😦

For me it worked too for my anaconda3 environment!!! I have deleted \anaconda3\envs\test\Lib\site-packages\tensorflow folder and run: pip uninstall tensorflow pip uninstall tensorflow-gpu conda install tensorflow-gpu

The problem is that you updated the tensorflow but not tensorflow_gpu.

pip install --upgrade tensorflow pip install --upgrade tensorflow-gpu

The above-mentioned commands will uninstall and reinstall the tensorflow correctly. Best wishes.

I got this error after “pip3 install --upgrade tensorflow” .

#Got the same issue Win 10 + CUDA 9.2 + Anaconda 1.8.7 Upgrated from Tensorflow 1.8 to Tensorflow 1.9 Uninstalling/reinstalling doesn’t work.

Even complete remove Tensorflow GPU witn only CPU version left doesn’t help. Seems that this is not just GPU ver. but the general tensorflow/keras api problem. What ver of keras should be installed with this release?

Now i’m thinking of complete remove an Anaconda to rebuild everything again (((

UPD: Found partial solution for win 10 - Anaconda:

  1. run Anaconda under Admin
  2. via “environements” uninstall Keras
  3. Run Anaconda prompt under Admin and pip uninstall tensorflow and then pip uninstall tensorflow-gpu
  4. reboot your comp
  5. run Anaconda under Admin and via “environements” install Keras 2.2.0 and all available keras packages
  6. while solving packages, it’ll propose you to install all necessary Tensorflow 1.8. packages.
  7. Apply.

Now i have tensorflow GPU devices listed and Keras finally found proper GPU backend Checked it via monitoring devices usage.

Hope it’ll be helpful for someone

Installing 1.8.0 instead of the (currently) latest 1.11.0 worked on the Udacity AMI (Ubuntu 16.0.4).

We do have pip tests on windows, not sure how we missed this.

@gunan @case540 @amitpatankar

I this is a widespread problem we should have seen it in the windows tests, no? Or do we not have Windows pip tests? Maybe we should for release. 😕

Hi, just had the same problem while installing tensorflow 1.12.0 and keras 2.2.4 on Windows 10. I managed the installations with Anaconda3.

PROBLEM SOLVED after reading the answers above and doing the following steps:

  1. Uninstalled all packages that begin with “tensorflow” and “keras”.
  2. Re-installed “keras” and installed the dependencies Anaconda offered to install, which include tensorflow.

Grrrr pip.

Can we either add a short (python?) snippet to our install docs that people can run to upgrade safely?

Alternatively, could we (going forward) put the python files into a versioned directory, and have “tensorflow” be a link in site-packages? Would that work on Windows? Would it work in pip?

Could it be an issue similar to https://github.com/pypa/pip/issues/5020? We have --ignore-installed in documentation: https://www.tensorflow.org/install/install_windows According to the thread at that link, if this argument was passed some time in the past it could cause files from old versions to stay in site-packages.