googlecolab / colabtools

Python libraries for Google Colaboratory
Apache License 2.0
2.2k stars 723 forks source link

TypeError: 'type' object is not subscriptable when importing tensorflow_federated as tff #2780

Closed t-alanazi closed 2 years ago

t-alanazi commented 2 years ago

I'm working in colab notebook, and the importing of tff (import tensorflow_federated as tff) was working for months, but suddenly, now when I try to import tff as usual I faced this problem..

!pip install --quiet --upgrade tensorflow-federated !pip install --quiet --upgrade tensorflow-model-optimization !pip install --quiet --upgrade nest-asyncio

import nest_asyncio nest_asyncio.apply()

import numpy as np import tensorflow as tf import tensorflow_federated as tff from tensorflow_model_optimization.python.core.internal import tensor_encoding as te


TypeError Traceback (most recent call last)

in () 2 import numpy as np 3 import tensorflow as tf ----> 4 import tensorflow_federated as tff 5 6 from tensorflow_model_optimization.python.core.internal import tensor_encoding as te 7 frames /usr/local/lib/python3.7/dist-packages/tensorflow_federated/python/common_libs/structure.py in () 263 264 def to_odict(struct: Struct, --> 265 recursive: bool = False) -> collections.OrderedDict[str, Any]: 266 """Returns `struct` as an `OrderedDict`, if possible. 267 TypeError: 'type' object is not subscriptable Even when I run it in the colab tutorial itself! in this link https://colab.research.google.com/github/tensorflow/federated/blob/master/docs/tutorials/federated_learning_for_image_classification.ipynb I have the same issue! Appreciate any idea or suggestions!
craigcitro commented 2 years ago

The issue here is that TFF requires python 3.9+ (https://github.com/tensorflow/federated/pull/2724), but Colab is still using Python 3.7.

Closing as duplicate of #2165.