No module named 'absl' error when I import tensorflow

130.4k Views Asked by At

I have anaconda installed on my Win 7 machine with a GTX1070.

I have been trying to install tensorflow gpu version for the past hour with no luck. I followed the tutorials on the tensorflow website to no success. They ask for you to install CUDA 8.0 and Cudll 6.0 which I do. I then add the location of cudnn64_6.dll, cudart64_80.dll and the libnvvp folder to my path variables. I then set up a virtual environment in conda and run the following command:

(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu 

I believe when I do this, it installs tensorflow 1.5 which seems to require CUDA tools 9.0 because I get an error saying that cudart64_80.dll cannot be found. So I update my CUDA tools to 9.0 and download the corresponding Cuda library. I then change my path variables. Now I dont get any missing dll errors however, I am now faced with the following error

ModuleNotFoundError: No module named 'absl'

Does anyone have any suggestions as to what I can do from here on?

12

There are 12 best solutions below

0
On

Try:

conda install tensorflow
conda install -c anaconda absl-py

This worked for me.

For more information see: https://anaconda.org/anaconda/absl-py

0
On

Try another version of absl-py. My default absl version is 0.8.1 and python is 3.6:

$pip install absl-py==0.8.0

works for me.

Or change my environment python version to 3.7 also works.

0
On

If you are using Anaconda make sure you install jupyter notebook from Home. if not you can import it from python CLI but it will give "No module named 'absl' error when importing TensorFlow"

0
On

Find the absl-py related folder in your site-packages folder and delete it. Try reinstalling pip3 install absl-py. I solved this way, I hope to be useful to you.

0
On

This is quite late but still worth posting. What they don't tell you on the NVidia website is that there is one more path you need to add to your environment variables. The path is;

c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\extras\CUPTI\libx64

It may not be exactly the same on your installation as it depends on where you installed your CUDA tools.

You could also just use pip to install TF GPU version but pip installs TF 1.1 which is fairly old.

1
On

Here is how I solved it in my end.

I was getting the error even though absl-py was already installed.

When I used pip install absl-py I got the following error:

Requirement already satisfied: absl-py in c:\users\stack\appdata\local\programs\python\python38\lib\site-packages (0.9.0)
Requirement already satisfied: six in c:\users\stack\appdata\local\programs\python\python38\lib\site-packages (from absl-py) (1.15.0)

I fixed it by reinstalling, i.e. by using:

pip uninstall absl-py
pip install absl-py

Then I faced a similar error with wrapt: ModuleNotFoundError: No module named 'wrapt'

Fixed wrapt as well by uninstalling and then installing it again.

pip uninstall wrapt
pip install wrapt
0
On

For me, "pip3 install absl-py" don't work:

I received: "ModuleNotFoundError: No module named 'absl' ", when I was trying import tensorflow:

import tensorflow Traceback (most recent call last): File "", line 1, in File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/init.py", line 22, in from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/init.py", line 63, in from tensorflow.python.framework.framework_lib import * # pylint: disable=redefined-builtin File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/framework_lib.py", line 25, in from tensorflow.python.framework.ops import Graph File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 55, in from tensorflow.python.platform import app File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 24, in from tensorflow.python.platform import flags File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/flags.py", line 25, in from absl.flags import * # pylint: disable=wildcard-import ModuleNotFoundError: No module named 'absl'

But if I compile absl-py from scratch, all goes right:

jk@D17:~/py/004/abseil-py-master$ python setup.py install

running install

running bdist_egg running egg_info

.......

Using /opt/anaconda3/lib/python3.6/site-packages

Finished processing dependencies for absl-py==0.4.0

and then:

import tensorflow

is OK

0
On

You can use the Anaconda GUI to install absl-py pack to solve the problem:

Select the uninstall columnand search absl-py to apply it.

0
On

I got the No module named absl error when I tried to install tf-nightly 2.9.0.dev20220203 on my Ubuntu 20.04.3 machine.

Reinstalling absl-py did not directly worked. While reinstalling absl, I got this error: ERROR: tf-nightly 2.9.0.dev20220203 has requirement gast<=0.4.0,>=0.2.1, but you'll have gast 0.5.3 which is incompatible.

So I uninstalled absl-py:

pip uninstall absl-py

Then downgraded gast:

pip uninstall gast

pip install gast==0.4.0

Finally, pip install absl-py

1
On

This was caused by a Python version issue for me. I had the absl package installed on my Python 2.x, but my Python 3.x didn't have it. So I just made sure that both Pythons on my machine had the package installed:

pip install absl-py
pip3 install absl-py

0
On

I was facing the same issues and pip (or pip3) install absl-py was not working.

python --version showed I was using the wrong python version (2.7). So I changed the python version to 3.5 (https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3)

This worked for me.

0
On

In hopes that this might help someone in the future. I had similar issues installing/using tensorflow and by extension the absl python package. There were some issues relating to a pure pip installation so I had to find an alternate route.

This is the process I followed.

Download and install miniconda:

wget https://repo.continuum.io/miniconda/Miniconda3-3.7.0-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda

add conda to PATH (Optional):

export PATH="$HOME/miniconda/bin:$PATH"

activate the conda environment:

source $HOME/miniconda/bin/activate

At this point you should have (base) as your sourced condo environment. From this environment perform the following:

conda create -n tensorflow python=3.7
activate tensorflow

Just to note, at this point you should be working in the (tensorflow) environment. It would have replaced the base environment. It is also the env where you would run your tensorflow related job (that failed and brought you here).


pip install --ignore-installed --upgrade tensorflow
pip install absl-py

At this point you might need to install additional dependencies such as numpy.

My goal was to be able to run tensorflow tools and this worked for my ends. Hope it may be useful to someone else in the future.