New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'abs' #20778

Closed
ghost opened this Issue Jul 13, 2018 · 33 comments

Comments

Projects
None yet
@ghost
Copy link

ghost commented Jul 13, 2018

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

@tensorflowbutler

This comment has been minimized.

Copy link
Member

tensorflowbutler commented Jul 13, 2018

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

@martinwicke

This comment has been minimized.

Copy link
Member

martinwicke commented Jul 13, 2018

@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. :/

@gunan

This comment has been minimized.

Copy link
Member

gunan commented Jul 13, 2018

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

@case540

This comment has been minimized.

Copy link
Member

case540 commented Jul 13, 2018

Do we only have pip tests for Bazel builds (release we only look at CMake Windows builds)

@martinwicke

This comment has been minimized.

Copy link
Member

martinwicke commented Jul 13, 2018

I guess that means patch release time. Only needed for Windows, I guess?

@case540

This comment has been minimized.

Copy link
Member

case540 commented Jul 13, 2018

This issue seems to suggest a fix...
tensorflow/probability#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

@martinwicke

This comment has been minimized.

Copy link
Member

martinwicke commented Jul 13, 2018

Nice find! @RyenAng can you check whether that solution works for you? We did upgrade our protobuf dependency, and while it's regrettable that the failure is so obscure, it's somewhat beyond our control.

@prsahuGloob

This comment has been minimized.

Copy link

prsahuGloob commented Jul 14, 2018

@case540 This didn't work for me. I tried this on Windows 7

@martinwicke

This comment has been minimized.

Copy link
Member

martinwicke commented Jul 14, 2018

@gunan

This comment has been minimized.

Copy link
Member

gunan commented Jul 14, 2018

I just reproduced the problem on my windows laptop. I am really surprised, because all the python files are there!
I can manually run that exact line (which fails with a very similar issue) and it is found, but it is not found during import tensorflow. Also, it looks to be specific to keras.
@annarev is it possible we have another API generation problem?
@case540 did we do anything special for keras API generation?

I will see why our tests did not catch this. Maybe our unit tests just do from tensorflow.python.foo import bar and these all pass?

@annarev

This comment has been minimized.

Copy link
Member

annarev commented Jul 14, 2018

Hm we had a change a couple months ago that removed _impl directory. I don't see _impl directory under
https://github.com/tensorflow/tensorflow/tree/r1.9/tensorflow/python/keras
So, it is strange that an import fails on upgrade.
Could it be that some old file is there after upgrade?

@annarev

This comment has been minimized.

Copy link
Member

annarev commented Jul 14, 2018

Could it be an issue similar to pypa/pip#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.

@gunan

This comment has been minimized.

Copy link
Member

gunan commented Jul 14, 2018

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.

@Red-Eyed

This comment has been minimized.

Copy link

Red-Eyed commented Jul 14, 2018

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
@martinwicke

This comment has been minimized.

Copy link
Member

martinwicke commented Jul 14, 2018

@gunan

This comment has been minimized.

Copy link
Member

gunan commented Jul 15, 2018

@LeoFH

This comment has been minimized.

Copy link

LeoFH commented Jul 15, 2018

#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

@Red-Eyed

This comment has been minimized.

Copy link

Red-Eyed commented Jul 15, 2018

I don't think that running something under admin could be a solution. Did you try to remove tensorflow from filesystem manually (I mean w/o using pip just all folders in anaconda/env)?

@LeoFH

This comment has been minimized.

Copy link

LeoFH commented Jul 15, 2018

Running under Admin is important cause Anaconda itself does't allow (at least in my case)
to change the environement with simple user rights

Anaconda prompt under user also is not allowed to make changes in some folders.

Also sometimes people have several different environements (as me, for example) so, searching every folder for manually deleting becomes a problem itself.

My way is totally worked for me.
It is simple, effective, and looks to be the same for everyone.

@yzy1996

This comment has been minimized.

Copy link

yzy1996 commented Jul 17, 2018

When I update my python version from 3.6.2 to 3.6.6, I meet this problem.

@bhakthan

This comment has been minimized.

Copy link

bhakthan commented Jul 29, 2018

pip install --upgrade keras
did the trick (especially in conda installed tensorflow-gpu)
Env: Windows 10 , CUDA 9 + CUDNN 7, Python3.6(Anaconda5.2)

@JunGao95

This comment has been minimized.

Copy link

JunGao95 commented Aug 7, 2018

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...:(

@gunan

This comment has been minimized.

Copy link
Member

gunan commented Aug 7, 2018

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.

@gunan gunan closed this Aug 7, 2018

@wajahat57

This comment has been minimized.

Copy link

wajahat57 commented Aug 18, 2018

@gunan's solution worked for me with WinPython 3.5 x64 , TensorFlow 1.10.0 and keras 2.2.2

@maciejewskimichal

This comment has been minimized.

Copy link

maciejewskimichal commented Sep 12, 2018

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

@AramNasser

This comment has been minimized.

Copy link

AramNasser commented Sep 20, 2018

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.

@moorejee

This comment has been minimized.

Copy link

moorejee commented Oct 7, 2018

In my windows laptop, i get fixed this error by uninstalling tensorflow, remove tensorflow things' files in site-packages and install tensorflow again

@nateGeorge

This comment has been minimized.

Copy link

nateGeorge commented Oct 10, 2018

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

@Bjoux2

This comment has been minimized.

Copy link

Bjoux2 commented Nov 5, 2018

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

@zubairahmed-ai

This comment has been minimized.

Copy link

zubairahmed-ai commented Nov 22, 2018

After I upgraded tensorflow to the latest version 1.12 my keras was still left at 2.1.5 I got this error
So I switched to another conda environment with TF 1.9 and Keras 2.2.4 and it just worked

@ishakdolek

This comment has been minimized.

Copy link

ishakdolek commented Dec 4, 2018

I got this error after upgrade tensorflow. I uninstall tensorflow after that install tensorflow but I cloudn't fix this problem. Finally I uninstall tensorflow and delete tensorflow folder in python site package ( C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\site-packages ). By the way, The problem is fixed.(OS:Windows 10 ; Using Visual Studio Code)

@stkuzmin

This comment has been minimized.

Copy link

stkuzmin commented Dec 13, 2018

Hi, I have a similar problem. I am using tf and keras. I found out that do not have some models from keras and decided to install keras in tensorflow environment. After installation, during compilation of the program I've got this ;
"from tensorflow.python.keras._impl.keras.backend import abs
ImportError: cannot import name 'abs' "
System: Win10x64, python 3.6, tensorflow 1-12.0, keras 2.2.4-0

@zahaviguy

This comment has been minimized.

Copy link

zahaviguy commented Dec 18, 2018

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment