Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

cannot import name 'OrderedDict' from 'typing' #5412

Closed
1 of 10 tasks
rattlesnakey opened this issue Sep 15, 2021 · 7 comments
Closed
1 of 10 tasks

cannot import name 'OrderedDict' from 'typing' #5412

rattlesnakey opened this issue Sep 15, 2021 · 7 comments

Comments

@rattlesnakey
Copy link

rattlesnakey commented Sep 15, 2021

Checklist

  • I have verified that the issue exists against the main branch of AllenNLP.
  • I have read the relevant section in the contribution guide on reporting bugs.
  • I have checked the issues list for similar or identical bug reports.
  • I have checked the pull requests list for existing proposed fixes.
  • I have checked the CHANGELOG and the commit log to find out if the bug was already fixed in the main branch.
  • I have included in the "Description" section below a traceback from any exceptions related to this bug.
  • I have included in the "Related issues or possible duplicates" section beloew all related issues and possible duplicate issues (If there are none, check this box anyway).
  • I have included in the "Environment" section below the name of the operating system and Python version that I was using when I discovered this bug.
  • I have included in the "Environment" section below the output of pip freeze.
  • I have included in the "Steps to reproduce" section below a minimally reproducible example.

Description

Python traceback:cannot import name 'OrderedDict' from 'typing'

Related issues or possible duplicates

  • None

Environment

OS:

Python version:3.7

Output of pip freeze:

allennlp==2.7.0
argcomplete @ file:///tmp/build/80754af9/argcomplete_1618920853202/work
argon2-cffi==21.1.0
attrs @ file:///tmp/build/80754af9/attrs_1620827162558/work
backcall @ file:///home/ktietz/src/ci/backcall_1611930011877/work
backports.csv==1.0.7
base58==2.1.0
beautifulsoup4==4.10.0
bleach==4.1.0
blis==0.7.4
boto3==1.18.42
botocore==1.21.42
cached-property==1.5.2
cachetools==4.2.2
catalogue==2.0.6
certifi==2021.5.30
cffi==1.14.6
chardet==4.0.0
charset-normalizer==2.0.4
checklist==0.0.11
cheroot==8.5.2
CherryPy==18.6.1
click==7.1.2
configparser==5.0.2
cryptography==3.4.8
cycler==0.10.0
cymem==2.0.5
datasets==1.6.2
debugpy==1.4.3
decorator==5.1.0
defusedxml @ file:///tmp/build/80754af9/defusedxml_1615228127516/work
dill==0.3.4
docker-pycreds==0.4.0
entrypoints==0.3
fairscale==0.4.0
feedparser==6.0.8
filelock==3.0.12
fsspec==2021.8.1
future==0.18.2
gitdb==4.0.7
GitPython==3.1.23
google-api-core==2.0.1
google-auth==2.1.0
google-cloud-core==2.0.0
google-cloud-storage==1.42.1
google-crc32c==1.1.2
google-resumable-media==2.0.2
googleapis-common-protos==1.53.0
h5py==3.4.0
huggingface-hub==0.0.16
idna==3.2
importlib-metadata==4.8.1
iniconfig==1.1.1
ipykernel==6.4.1
ipython==7.27.0
ipython-genutils @ file:///tmp/build/80754af9/ipython_genutils_1606773439826/work
ipywidgets==7.6.4
iso-639==0.4.5
jaraco.classes==3.2.1
jaraco.collections==3.4.0
jaraco.functools==3.3.0
jaraco.text==3.5.1
jedi @ file:///tmp/build/80754af9/jedi_1611333758854/work
Jinja2 @ file:///tmp/build/80754af9/jinja2_1624781299557/work
jmespath==0.10.0
joblib==1.0.1
jsonnet==0.17.0
jsonschema @ file:///Users/ktietz/demo/mc3/conda-bld/jsonschema_1630511932244/work
jupyter==1.0.0
jupyter-client==7.0.2
jupyter-console==6.4.0
jupyter-core @ file:///tmp/build/80754af9/jupyter_core_1612213308260/work
jupyterlab-pygments==0.1.2
jupyterlab-widgets==1.0.1
kiwisolver==1.3.2
lmdb==1.2.1
lxml==4.6.3
MarkupSafe @ file:///tmp/build/80754af9/markupsafe_1621528142364/work
matplotlib==3.4.3
matplotlib-inline==0.1.3
mistune @ file:///tmp/build/80754af9/mistune_1594373098390/work
more-itertools==8.9.0
multiprocess==0.70.12.2
munch==2.5.0
murmurhash==1.0.5
nb-conda==2.2.1
nb-conda-kernels @ file:///tmp/build/80754af9/nb_conda_kernels_1606775986548/work
nbclient==0.5.4
nbconvert==6.1.0
nbformat @ file:///tmp/build/80754af9/nbformat_1617383369282/work
nest-asyncio @ file:///tmp/build/80754af9/nest-asyncio_1613680548246/work
nltk==3.6.2
notebook==6.4.3
numpy==1.21.2
overrides==3.1.0
packaging @ file:///tmp/build/80754af9/packaging_1625611678980/work
pandas==1.1.5
pandocfilters @ file:///tmp/build/80754af9/pandocfilters_1605120451932/work
parso @ file:///tmp/build/80754af9/parso_1617223946239/work
pathtools==0.1.2
pathy==0.6.0
patternfork-nosql==3.6
pdfminer.six==20201018
pexpect @ file:///tmp/build/80754af9/pexpect_1605563209008/work
pickleshare @ file:///tmp/build/80754af9/pickleshare_1606932040724/work
Pillow==8.3.2
pluggy==1.0.0
portend==2.7.1
preshed==3.0.5
prometheus-client @ file:///tmp/build/80754af9/prometheus_client_1623189609245/work
promise==2.3
prompt-toolkit==3.0.20
protobuf==3.17.3
psutil==5.8.0
ptyprocess @ file:///tmp/build/80754af9/ptyprocess_1609355006118/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl
py==1.10.0
pyarrow==5.0.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
pydantic==1.8.2
Pygments @ file:///tmp/build/80754af9/pygments_1629234116488/work
pyparsing @ file:///home/linux1/recipes/ci/pyparsing_1610983426697/work
pyrsistent==0.18.0
pytest==6.2.5
python-dateutil @ file:///tmp/build/80754af9/python-dateutil_1626374649649/work
python-docx==0.8.11
pytz==2021.1
PyYAML==5.4.1
pyzmq @ file:///tmp/build/80754af9/pyzmq_1628267913491/work
qtconsole==5.1.1
QtPy==1.11.0
regex==2021.8.28
requests==2.26.0
rsa==4.7.2
s3transfer==0.5.0
sacremoses==0.0.45
scikit-learn==0.24.2
scipy==1.7.1
seaborn==0.11.2
Send2Trash==1.8.0
sentencepiece==0.1.96
sentry-sdk==1.3.1
sgmllib3k==1.0.0
shortuuid==1.0.1
six @ file:///tmp/build/80754af9/six_1623709665295/work
sklearn==0.0
smart-open==5.2.1
smmap==4.0.0
sortedcontainers==2.4.0
soupsieve==2.2.1
spacy==3.1.2
spacy-legacy==3.0.8
sqlitedict==1.7.0
srsly==2.4.1
subprocess32==3.5.4
tempora==4.1.1
tensorboardX==2.4
termcolor==1.1.0
terminado==0.12.1
testpath @ file:///tmp/build/80754af9/testpath_1624638946665/work
thinc==8.0.10
threadpoolctl==2.2.0
tokenizers==0.10.3
toml==0.10.2
torch==1.9.0
torchtext==0.10.0
torchvision==0.10.0
tornado @ file:///tmp/build/80754af9/tornado_1606942283357/work
tqdm==4.49.0
traitlets==5.1.0
transformers==4.4.2
typer==0.3.2
typing==3.7.4.3
typing-extensions==3.10.0.2
urllib3==1.26.6
wandb==0.12.1
wasabi==0.8.2
wcwidth @ file:///Users/ktietz/demo/mc3/conda-bld/wcwidth_1629357192024/work
webencodings==0.5.1
widgetsnbextension==3.5.1
xxhash==2.0.2
zc.lockfile==2.0
zipp @ file:///tmp/build/80754af9/zipp_1625570634446/work

Steps to reproduce

Example source:

@AkshitaB
Copy link
Contributor

@rattlesnakey Can you share what command/code snippet you are running that leads to this error?

@Switchsyj
Copy link

Switchsyj commented Sep 18, 2021

I also run into this bug while running this snippet in conda command line:
from allennlp.modules.conditional_random_field import ConditionalRandomField
And it shows:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/syj/miniconda3/envs/medNER/lib/python3.7/site-packages/allennlp/modules/__init__.py", line 8, in <module> from allennlp.modules.backbones import Backbone File "/home/syj/miniconda3/envs/medNER/lib/python3.7/site-packages/allennlp/modules/backbones/__init__.py", line 3, in <module> from allennlp.modules.backbones.vilbert_backbone import VilbertBackbone File "/home/syj/miniconda3/envs/medNER/lib/python3.7/site-packages/allennlp/modules/backbones/vilbert_backbone.py", line 10, in <module> from allennlp.modules.transformer import ( File "/home/syj/miniconda3/envs/medNER/lib/python3.7/site-packages/allennlp/modules/transformer/__init__.py", line 126, in <module> from allennlp.modules.transformer.layer_norm import LayerNorm File "/home/syj/miniconda3/envs/medNER/lib/python3.7/site-packages/allennlp/modules/transformer/layer_norm.py", line 3, in <module> from allennlp.modules.transformer.transformer_module import TransformerModule File "/home/syj/miniconda3/envs/medNER/lib/python3.7/site-packages/allennlp/modules/transformer/transformer_module.py", line 12, in <module> from allennlp.nn.parallel import ShardedModuleMixin File "/home/syj/miniconda3/envs/medNER/lib/python3.7/site-packages/allennlp/nn/parallel/__init__.py", line 2, in <module> from allennlp.nn.parallel.ddp_accelerator import ( File "/home/syj/miniconda3/envs/medNER/lib/python3.7/site-packages/allennlp/nn/parallel/ddp_accelerator.py", line 2, in <module> from typing import ( ImportError: cannot import name 'OrderedDict' from 'typing' (/home/syj/miniconda3/envs/medNER/lib/python3.7/typing.py)
My local environment is python 3.7+pytorch 1.9(cuda11) with allennlp 2.7.0.

@Switchsyj
Copy link

And I sloved this by deleting from typing import OrderedDict, and adding from collections import OrderedDict.

@cyilu
Copy link

cyilu commented Sep 21, 2021

And I sloved this by deleting from typing import OrderedDict, and adding from collections import OrderedDict.

Thanks. I solved this problem by your method. But I meet another problem:
"StateDictType = Union[Dict[str, torch.Tensor], OrderedDict[str, torch.Tensor]]
TypeError: 'type' object is not subscriptable"

Do you know how to solve it?

Any help will be appreciated.

@rattlesnakey
Copy link
Author

rattlesnakey commented Sep 21, 2021 via email

@cyilu
Copy link

cyilu commented Sep 21, 2021

@rattlesnakey Thanks. It can solve this problem. But I meet another problem:
return types.CodeType( TypeError: an integer is required (got type bytes)

In addition, before that, I meet a problem:
from ._check_build import check_build # noqa ImportError: dlopen: cannot load any more object with static TLS

I solve it by degrading scikit-learn to 0.20.3, how do you solve it?

Any help will be appreciated.

@github-actions
Copy link

github-actions bot commented Oct 4, 2021

This issue is being closed due to lack of activity. If you think it still needs to be addressed, please comment on this thread 👇

@github-actions github-actions bot added the stale label Oct 4, 2021
@github-actions github-actions bot closed this as completed Oct 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants