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
- fallback to import from typing_extensions for older python version Summary: https://github.com/facebookresearch/d2go/issues/60#issuecomment-863149605 #stamp2ship Differential Revision: D29495802 fb... — committed to zhanghang1989/d2go by wat3rBro 3 years ago
- fallback to import from typing_extensions for older python version Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/98 https://github.com/facebookresearch/d2go/issues/60... — committed to facebookresearch/d2go by wat3rBro 3 years ago
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
finalin thetypingmodule - but Python 3.8 has one. Solution: (this may not be the legal way, but solved my issue) I thought thatfinalmethod 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 finaland, in the class
ModelExportMethod,#@finalThat’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.pytofrom typing_extensions import finalif you’re using python3.7 or below