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

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

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.

Issues in setting up the environment for TensorFlow Federated on Colab

I am new to Federated Learning, and I am trying to get started with TensorFlow Federated. While working on the tutorial "Federated Learning for Image Classification" on Colab, I tried to install TensorFlow Federated, but was met with these errors:
ERROR: tensorflow 2.5.0 requires tensorboard~=2.5, which is not installed.
ERROR: tensorflow 2.5.0 has requirement grpcio~=1.34.0, but you'll have grpcio 1.37.1 which is incompatible.
ERROR: tensorflow 2.5.0 has requirement keras-nightly~=2.5.0.dev, but you'll have keras-nightly 2.6.0.dev2021062500 which is incompatible.
ERROR: spacy 2.2.4 has requirement tqdm<5.0.0,>=4.38.0, but you'll have tqdm 4.28.1 which is incompatible.
ERROR: pymc3 3.11.2 has requirement cachetools>=4.2.1, but you'll have cachetools 3.1.1 which is incompatible.
ERROR: fbprophet 0.7.1 has requirement tqdm>=4.36.1, but you'll have tqdm 4.28.1 which is incompatible.
ERROR: datascience 0.10.6 has requirement folium==0.2.1, but you'll have folium 0.8.3 which is incompatible.
ERROR: tensorflow-privacy 0.6.1 has requirement attrs>=21.2.0, but you'll have attrs 19.3.0 which is incompatible.
After installing the versions of the libraries mentioned here, I found that there still exist some internal conflicts with the installed libraries. Has anyone else faced this issue? Would be great to get some pointers on this!
You may try the following commands to reset the environment:
!pip uninstall tensorflow
!pip uninstall tf-nightly
!pip uninstall tensorflow-federated
!pip install tensorflow
!pip install tensorflow-federated
!pip install tensorflow-federated-nightly

Unable to import tensorflow_addons

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

installing tensorflow_transform and apache_beam on Datalab

I'm going over these example from google-cloud Coursera courses, and although they worked till a few weeks ago, I can't install tf.transform or apache_beam on Datalab anymore.
https://github.com/GoogleCloudPlatform/training-data-analyst/blob/master/courses/machine_learning/feateng/tftransform.ipynb
https://github.com/GoogleCloudPlatform/training-data-analyst/blob/master/courses/machine_learning/deepdive/06_structured/4_preproc_tft.ipynb
When installing tensorflow_transform I get the following errors:
%bash
pip install --upgrade --force tensorflow_transform==0.6.0
twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed.
datalab 1.1.3 has requirement six==1.10.0, but you'll have six 1.11.0 which is incompatible.
gapic-google-cloud-pubsub-v1 0.15.4 has requirement oauth2client<4.0dev,>=2.0.0, but you'll have oauth2client 4.1.2 which is incompatible.
proto-google-cloud-pubsub-v1 0.15.4 has requirement oauth2client<4.0dev,>=2.0.0, but you'll have oauth2client 4.1.2 which is incompatible.
apache-airflow 1.9.0 has requirement bleach==2.1.2, but you'll have bleach 1.5.0 which is incompatible.
apache-airflow 1.9.0 has requirement funcsigs==1.0.0, but you'll have funcsigs 1.0.2 which is incompatible.
google-cloud-monitoring 0.28.0 has requirement google-cloud-core<0.29dev,>=0.28.0, but you'll have google-cloud-core 0.25.0 which is incompatible.
proto-google-cloud-datastore-v1 0.90.4 has requirement oauth2client<4.0dev,>=2.0.0, but you'll have oauth2client 4.1.2 which is incompatible.
pandas-gbq 0.3.0 has requirement google-cloud-bigquery>=0.28.0, but you'll have google-cloud-bigquery 0.25.0 which is incompatible.
googledatastore 7.0.1 has requirement httplib2<0.10,>=0.9.1, but you'll have httplib2 0.11.3 which is incompatible.
googledatastore 7.0.1 has requirement oauth2client<4.0.0,>=2.0.1, but you'll have oauth2client 4.1.2 which is incompatible.
Cannot uninstall 'dill'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
The tensorflow version on my Datalab instance was 1.4.
I had to add this one line of code to update tensorflow to 1.10.1
%bash
pip install --upgrade --force-reinstall pip==10.0.1
pip install tensorflow==1.10.1
pip install tensorflow_transform
my environment:
apache-airflow==1.9.0
apache-beam==2.6.0
tensorflow==1.10.1
tensorflow-metadata==0.9.0
tensorflow-tensorboard==0.4.0rc3
tensorflow-transform==0.8.0
The current version of Datalab uses TensorFlow 1.8, so please change the notebook cell in question to:
%bash
pip uninstall -y google-cloud-dataflow
pip install --upgrade --force tensorflow_transform==0.8.0 apache-beam[gcp]
I've updated and checked in the two notebooks linked above.
Another problem might be that you are using Python 2. Datalab by default now uses Python 3 and your pip install (above) happens in Python 3 even if the kernel is Python 2 because %%bash opens up a new shell in which the conda activate of Python 2 has not happened.
To make sure the pip install happens in Python 2, change your pip install of apache-beam[gcp] as follows:
%%bash
source activate py2env
conda install -y dill pytz # do this for all the distutils complaints
pip uninstall -y google-cloud-dataflow
pip install --upgrade --force tensorflow_transform==0.8.0 apache-beam[gcp]

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