Reputation: 102
I've been using colab for deep learning for a over a month and all of a sudden import tensorflow_docs as tfdocs
stopped working. Is anyone encountering the same issues???
I'm running tf.version 2.8.2
> !pip install git+https://github.com/tensorflow/docs
>
> import tensorflow_docs as tfdocs
> import tensorflow_docs.modeling
> import tensorflow_docs.plots
Error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-10-8469b6568dc0> in <module>()
2 get_ipython().system('pip install git+https://github.com/tensorflow/docs')
3
----> 4 import tensorflow_docs as tfdocs
5 import tensorflow_docs.modeling
6 import tensorflow_docs.plots
4 frames
/usr/local/lib/python3.7/dist-packages/tensorflow_docs/api_generator/reference_resolver.py in ReferenceResolver()
86 py_module_names: Union[list[str], dict[str, str]],
87 link_prefix: Optional[str] = None,
---> 88 physical_path: Optional[dict[str, str]] = None,
89 ):
90 """Initializes a Reference Resolver.
TypeError: 'type' object is not subscriptable
UPDATE 01-Sep-2022
I updated python in colab to 3.9.1 using @Kor suggestion and confirmed it. Then ran:
> !pip install git+https://github.com/tensorflow/docs
>
> import tensorflow_docs as tfdocs
The tensorflow doc completed installation but still threw an error on import:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-15-2bc3446903cd> in <module>
----> 1 import tensorflow_docs as tfdocs
2 import tensorflow_docs.modeling
3 import tensorflow_docs.plots
4
5 print("Version: ", tf.__version__)
ModuleNotFoundError: No module named 'tensorflow_docs'
Upvotes: 4
Views: 2379
Reputation: 1
After
!pip install git+https://github.com/tensorflow/docs
Open (if you are using Colab)
/usr/local/lib/python3.7/dist-packages/tensorflow_docs/api_generator/reference_resolver.py
and add from __future__ import annotations
at the BEGINNING OF THE FILE and then import
import tensorflow_docs as tfdocs
import tensorflow_docs.modeling
import tensorflow_docs.plots
Source: https://github.com/tensorflow/docs/pull/2116/files
Upvotes: 0
Reputation: 48
I assuming you are using Google Colab. As 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!
Upvotes: 1
Reputation: 8180
---> 88 physical_path: Optional[dict[str, str]] = None,
89 ):
90 """Initializes a Reference Resolver.
TypeError: 'type' object is not subscriptable
This error is caused by the dict[str, str]
line. This is PEP-585 compliant code that works in Python 3.9, but it looks like Colab is still running Python 3.7, so it's failing.
Feel free to send us PRs adding from __future__ import annotations
to the affected files if you spot these, but ultimately we run 3.9 internally at Google so these may keep sneaking through.
Some other ideas that you might be able to make work:
strip-hints
Upvotes: 1
Reputation: 66
You can try this:
!pip install -q git+https://github.com/MJAHMADEE/docs
import tensorflow_docs as tfdocs
import tensorflow_docs.modeling
import tensorflow_docs.plots
Upvotes: 2
Reputation: 31
I had also a problem with a script using tensor flow in colab, that had been running for months without any problem. Suddenly I start having the same error as you mention:
TypeError: 'type' object is not subscriptable
The script finished in the following line, at the top of the script:
from tensorflow_docs.vis import embed
I have just commented the line, and the script started working again... :
# from tensorflow_docs.vis import embed
I hope this may help some of you having the same error.
Upvotes: 0
Reputation: 3414
I have this problem too, but sadly I don't have a solution. However, this is what I've tried so far:
tensorflow_docs
with !pip install git+https://github.com/tensorflow/docs@my_version
choosing as my_version
a commit from a few weeks ago.tensorflow_docs
in a different way, first downloading it with !git clone https://github.com/tensorflow/docs
and then installing it via !pip install docs/
All without success.
Anyway from the error it seems it is a problem of the tensorflow_docs
'ReferenceResolver
, it looks like it is not able to find the library. However with the following instruction tensorflow-docs
is found:
!pip3 freeze | grep tensorflow
Upvotes: 1