Unable to import tensorflow_addons - tensorflow

I did a pip install for the tensorflow_addons module. Then when I execute import tensorflow_addons, I'm getting the error below. How to fix this?
tf.version prints this'1.13.1'. but when I checked the versions through anaconda prompt conda list -n base I found these
tensorboard 2.1.1 pypi_0 pypi
tensorflow 2.1.0 pypi_0 pypi
tensorflow-addons 0.9.1 pypi_0 pypi
tensorflow-datasets 3.0.0 pypi_0 pypi
tensorflow-estimator 2.1.0 pypi_0 pypi
tensorflow-gpu 1.13.1 h0d30ee6_0 anaconda
tensorflow-metadata 0.21.2 pypi_0 pypi
I tried this on both Windows and Ubuntu systems. same error on both systems.
pip install output
Error image

I was having the same problem today on google colaboratory, but both solution did not work for me, maybe it's a problem with the current versions in 2022.
To solve the problem i had to tweak the two versions of tf and tf addons.
So if in the future you have the same problem try to change the number of the 2 versions.
In the end i manage to solve without reinstalling tf like this:
!pip install tensorflow-addons==0.16.1
import tensorflow_addons as tfa
This is enough right now.

I found the answer for this problem. There is some bug in the above versions of tensorflow and tensorflow-addons modules. All you have to do is pip install the below mentioned versions and it will work.
pip install --user tensorflow-addons==0.8.3
pip install --user tensorflow==2.2.0-rc3
now you can import tensorflow_addons. I simply checked the versions installed in google colab link given in the official tensor flow addons page and changed my versions to that.
The screen shot of google colab code

Google Colab
!pip install tensorflow-addons==0.8.3
!pip install tensorflow==2.2.0-rc3
And after that
import tensorflow_addons as tfa

On your conda environment
pip install tensorflow-addons

Before installing tensorflow-addons, please check the compatible version of tensorflow-addons with your TF & Python version.
You can refer this for compatibility match:
Source: https://github.com/tensorflow/addons
For checking TF version
tf.__version__
For checking Python version
!python --version
Let say you got TF version: 2.9.2 & Python version: 3.8.16. From the compatibility sheet, the latest version you can install is 'tensorflow-addons-0.19.0'
To install tensorflow-addons:
!pip install tensorflow-addons==0.19.0
Now, we can import tensorflow addons like this
import tensorflow_addons as tfa

Related

Mac M1 - tensorflow-dependent package installation not working

I am using a MacBook Pro M1 and try to install the package dmol-book, which has tensorflow-dependency, via pip3 install dmol-book==1.3.2 .
It throws the following error:
ERROR: Ignored the following versions that require a different python version: 1.0.1 Requires-Python >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3,!=3.4.*,<3.9; 1.1.0 Requires-Python >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,<3.9; 1.1.1 Requires-Python >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,<3.9
ERROR: Could not find a version that satisfies the requirement tensorflow>=2.7 (from dmol-book) (from versions: none)
ERROR: No matching distribution found for tensorflow>=2.7
I have installed tensorflow via
pip3 install tensorflow-macos
pip3 install tensorflow-metal
I can use tensorflow within python3:
>>> import tensorflow
>>> tensorflow.__version__
'2.11.0'
>>> tensorflow.__file__
'/Users/username/.pyenv/versions/3.10.7/envs/venv/lib/python3.10/site-packages/tensorflow/__init__.py'
but pip3 list does not list tensorflow, only
tensorboard 2.11.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.8.1
tensorboardX 2.5.1
tensorflow-estimator 2.11.0
tensorflow-macos 2.11.0
tensorflow-metal 0.7.0
tensorstore 0.1.28
tensorflow also shows up as a directory in the original virtual environment directory, that I created:
/Users/username/pathtovirtualenv/venv/lib/python3.10/site-packages/tensorflow
Can someone help me to resolve this issue?
Thanks in advance!
I think its because it does not find a version that satisfies the requirement as mentioned.

cannot import name 'trace' from 'tensorflow.python.profiler

My enviorment was working fine, getting back to it after a while and when I try to run tensorboard I face this error:
cannot import name 'trace' from 'tensorflow.python.profiler
I have these packages in my conda env tfgpu220:
spyder 5.3.0
spyder-kernels 2.3.0
tensorboard 2.2.2
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.8.1
tensorflow-gpu 2.2.0
tensorflow-gpu-estimator 2.2.0
tensorflow-io-gcs-filesystem 0.25.0
termcolor 1.1.0
text-unidecode 1.3
textdistance 4.2.2
tf-estimator-nightly 2.8.0.dev2021122109
Any help, Thx.
Please upgrade the Tensorflow version and then import trace.
pip install tensorflow --upgrade
Use the following statement to import trace.
from tf.profiler.experimental import Trace

How to Install tensorflow addons via conda

I cannot find it out. Does Conda support it?
conda install tensorflow-addons
cannot find out the package
You can find information related to TensorFlow Addons here. Currently, it looks like Conda does not support Tensorflow Addons yet. You will have to wait for it to be implemented in the future. Otherwise, you can use pip install tensorflow-addons.
You can use pip in your Anaconda environment to install tensorflow-addons.
pip install tensorflow-addons
then to use:
import tensorflow_addons as tfa
I was able to successfully import it and use InstanceNormalization
conda install -c esri tensorflow-addons
or
conda install -c esri/label/prerelease tensorflow-addons
https://anaconda.org/esri/tensorflow-addons
To install the latest version of addons, run the following:
pip install tensorflow-addons
To use addons:
import tensorflow as tf
import tensorflow_addons as tfa
For more information please refer the below link
Tensorflow-addons

Downgrading TensorFlow from 1.15 to 1.14 not working

I have a colab notebook which was running tf1.15.0. I need to downgrade it to 1.14.0. In a cell, it run the following:
!pip uninstall tensorflow==1.15.0
!pip install tensorflow==1.14.0
import tensorflow as tf
print(tf.__version__)
However, it outputs:
> 1.15.0
What am I doing wrong please?
CS
IF you have import tensorflow cell before uninstall, you may need to restart notebook to make it effective.
IF you have not, make sure you are running the correct pip in the same python environment as the notebook, such as:
import sys
!{sys.executable} -m pip install xx
Do you have TensorFlow-GPU installed in the system? Because this is the same issue I was facing earlier, so try downgrading TensorFlow-GPU.
pip install tensorflow-gpu==1.14
or any other version of tensorflow-gpu.

How to install Keras if the required version of setuptools is older than default?

I'm using conda 4.4.9. I have already installed TensorFlow and I want to install Keras as well.
Then I tried to activate my virtual environment and install Keras as below:-
activate tensorflow_env_001
pip install --ignore-installed --upgrade keras
Then I got the following error message:
tensorflow 1.9.0 has requirement setuptools<=39.1.0, but you'll have setuptools 39.2.0 which is incompatible
That means my setuptools is too new. In fact, I can run the TensorFlow codes without any error. But I just can't install Keras. I tried to update setuptools but that had just made the situation worse, as setuptools now become 40.0.0.
If I run conda list, and I will see this:-
That means all TensorFlow, Keras and setuptools are here. But when I tried to import Keras in my Python code, I just got ModuleNotFoundError: No module named 'keras'.
How can I properly install Keras? Many thanks!!
tensorflow 1.9.0 has requirement setuptools<=39.1.0, but you'll have setuptools 39.2.0 which is incompatible
i got same error.To downgrade your setuptools version you can use
pip install setuptools==39.1.0
hope this helps further for keras installations.
Try to remove the env
conda remove --name ENVNAME --all
Then create a new one but first upgrade the pip version
python -m pip install --upgrade pip
and then install tensorflow:
pip install --ignore-installed --upgrade tensorflow==1.9.0
It will automatically get (downgrade) your version of setuptools
#
# Name Version Build Channel
.......
python 3.5.6 he025d50_0
setuptools 39.1.0 pypi_0 pypi
six 1.12.0 pypi_0 pypi
tensorboard 1.9.0 pypi_0 pypi
tensorflow 1.9.0 pypi_0 pypi
termcolor 1.1.0 pypi_0 pypi
.....