d2go: ImportError: cannot import name 'final' from 'typing' (/usr/local/lib/python3.7/typing.py)

Hi I was trying to run D2go on google collab . Following were my steps

  • Install Conda in google collab
# Install conda and add channels to look for packages in
import sys
! wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
! chmod +x Anaconda3-2020.02-Linux-x86_64.sh
! bash ./Anaconda3-2020.02-Linux-x86_64.sh -b -f -p /usr/local
sys.path.append('/usr/local/lib/python3.7/site-packages/')
! conda update -n base -c defaults conda -y
! conda config --add channels bioconda
! conda config --add channels conda-forge
  • Install the rest of dependencies in step
!conda install pytorch torchvision cudatoolkit=11.0 -c pytorch
!python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
!python -m pip install 'git+https://github.com/facebookresearch/mobile-vision.git'
!git clone https://github.com/facebookresearch/d2go
%cd d2go 
!python -m pip install .
#install the pyyaml verision
!pip install pyyaml
!wget http://images.cocodataset.org/val2017/000000439715.jpg -q -O input.jpg
#run demo
!python demo.py --config-file faster_rcnn_fbnetv3a_C4.yaml --input /content/d2go/demo/input.jpg --output output1.jpg 

I get the following error I was wondering what changes are needed to be done ?

Traceback (most recent call last):
  File "demo.py", line 14, in <module>
    from d2go.model_zoo import model_zoo
  File "/usr/local/lib/python3.7/site-packages/d2go/model_zoo/model_zoo.py", line 8, in <module>
    from d2go.runner import create_runner
  File "/usr/local/lib/python3.7/site-packages/d2go/runner/__init__.py", line 10, in <module>
    from .default_runner import BaseRunner, Detectron2GoRunner, GeneralizedRCNNRunner
  File "/usr/local/lib/python3.7/site-packages/d2go/runner/default_runner.py", line 31, in <module>
    from d2go.export.caffe2_model_helper import update_cfg_from_pb_model
  File "/usr/local/lib/python3.7/site-packages/d2go/export/__init__.py", line 5, in <module>
    from . import caffe2  # noqa
  File "/usr/local/lib/python3.7/site-packages/d2go/export/caffe2.py", line 10, in <module>
    from d2go.export.api import ModelExportMethodRegistry, ModelExportMethod
  File "/usr/local/lib/python3.7/site-packages/d2go/export/api.py", line 32, in <module>
    from typing import final
ImportError: cannot import name 'final' from 'typing' (/usr/local/lib/python3.7/typing.py)

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 21 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Hi all. I too had this error. It is because D2Go expects python 3.8. Google Colab has Python 3.7 by default. In Python 3.7, there is no method final in the typing module - but Python 3.8 has one. Solution: (this may not be the legal way, but solved my issue) I thought that final method is not really important in D2Go. Hence, in Colab, go to Files (present on your left side margin).

If you have installed without conda environment: go to /content/d2go/d2go/export/api.py

If you have installed inside a conda environment: go to /usr/local/lib/python3.7/site-packages/d2go/export/api.py

double-click on api.py it opens python file on your right side comment the line as below

#from typing import final

and, in the class ModelExportMethod,

#@final

That’s it. Save the file. Close it. Run your codes as usual.

Hope it helps!

try modifying line 32 in /your/d2go/directory/export/api.py to from typing_extensions import final if you’re using python3.7 or below