ImportError: cannot import name 'final' from 'typing' (/usr/local/lib/python3.7/typing.py)
See original GitHub issueHi 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)
Issue Analytics
- State:
- Created 2 years ago
- Comments:21 (2 by maintainers)
Top Results From Across the Web
ImportError: cannot import name 'final' · Issue #126 - GitHub
I have this error message when starting autorecon on a Raspberry Pi: ImportError: cannot import name 'final' from 'typing' (/usr/lib/python3.7/ ...
Read more >ImportError: cannot import name 'Literal' from 'typing'
Literal was added to typing.py in 3.8, but you can use Literal in older versions anyway. First install typing_extensions ( pip install ...
Read more >Issue - Panther Knowledge Base
How do I resolve the error "ImportError: cannot import name 'Final' from 'typing' (/usr/local/lib/python3.7/typing.py)" when using Panther ...
Read more >How to Fix ImportError: Cannot Import Name in Python - Rollbar
The Python ImportError: cannot import name error occurs when an imported class is not accessible or is in a circular dependency.
Read more >pyinstaller command giving "ImportError: cannot import name ...
from typing import Protocol ImportError: cannot import name 'Protocol' from 'typing' (c:\users\claus\anaconda3\pkgs\python-3.7.0-hea74fb7_0\lib\typing.py)
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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 thetyping
module - but Python 3.8 has one. Solution: (this may not be the legal way, but solved my issue) I thought thatfinal
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
tofrom typing_extensions import final
if you’re using python3.7 or below