1

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)
<ipython-input-7-c8d605e9ca2e> in <module>()
      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 <module>()
    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!

2 Answers 2

3

The latest tensorflow_federated package need the Python version update to 3.9, hope this will help you.

Sign up to request clarification or add additional context in comments.

2 Comments

when I upgrade it to 3.9, I got this error for pip Traceback (most recent call last): File "/usr/local/bin/pip3", line 5, in <module> from pip._internal.cli.main import main ModuleNotFoundError: No module named 'pip' ! can you give me the right way to upgrade python version with pip?
you can try to use ‘conda create -n new_env_name python=3.9’ to create a new conda environment and install tff package
1

I struggled the same with Google Colab since the default Google Colab is in Python 3.7. Here's what I did to make Google Colab upgrade to Python 3.9

!wget -O mini.sh https://repo.anaconda.com/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh
!chmod +x mini.sh
!bash ./mini.sh -b -f -p /usr/local
!conda install -q -y jupyter
!conda install -q -y google-colab -c conda-forge
!python -m ipykernel install --name "py39" --user

Hope this helps you to move on as I did!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.