question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't import torchtext

See original GitHub issue

🐛 Bug

Describe the bug A clear and concise description of what the bug is.

Can’t import torchtext

To Reproduce Steps to reproduce the behavior:

$ python -c 'import torch; import torchtext'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/pytorch/text/torchtext/__init__.py", line 12, in <module>
    from . import data, datasets, prototype, functional, models, nn, transforms, utils, vocab, experimental
  File "/opt/pytorch/text/torchtext/datasets/__init__.py", line 3, in <module>
    from .ag_news import AG_NEWS
  File "/opt/pytorch/text/torchtext/datasets/ag_news.py", line 5, in <module>
    from torchdata.datapipes.iter import FileOpener, IterableWrapper
  File "/opt/conda/lib/python3.8/site-packages/torchdata-0.4.1-py3.8-linux-x86_64.egg/torchdata/__init__.py", line 9, in <module>
    from . import datapipes
  File "/opt/conda/lib/python3.8/site-packages/torchdata-0.4.1-py3.8-linux-x86_64.egg/torchdata/datapipes/__init__.py", line 9, in <module>
    from . import iter, map, utils
  File "/opt/conda/lib/python3.8/site-packages/torchdata-0.4.1-py3.8-linux-x86_64.egg/torchdata/datapipes/iter/__init__.py", line 64, in <module>
    from torchdata.datapipes.iter.transform.callable import (
  File "/opt/conda/lib/python3.8/site-packages/torchdata-0.4.1-py3.8-linux-x86_64.egg/torchdata/datapipes/iter/transform/callable.py", line 10, in <module>
    from torch.utils.data.datapipes.utils.common import _check_lambda_fn
ImportError: cannot import name '_check_lambda_fn' from 'torch.utils.data.datapipes.utils.common' (/opt/pytorch/pytorch/torch/utils/data/datapipes/utils/common.py)

Expected behavior A clear and concise description of what you expected to happen.

import should work

Screenshots If applicable, add screenshots to help explain your problem.

N/A

Environment

torch_commit: https://github.com/pytorch/pytorch/commit/701b3dd77380bb0f7e696c9511b8ee765488687d torchtext_commit: https://github.com/pytorch/text/commit/0208a0ed4fa5f55e1e50cc26c24cb7a132e0d62f

Additional context Add any other context about the problem here.

However, using this torchtext commit works 5c402176d8456d572cad3ccd295fcfed2021e8d4. I guess https://github.com/pytorch/text/pull/1961 is related.

cc @abhinavarora @ejguan @ngimel

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ejguancommented, Oct 26, 2022

Understood, torchtext now adds a hard dependency on torchdata. So if you install everything from scratch, you have to install torchdata from scratch as well. And, for TorchText side, on the main branch, a specific version of torchdata should be specified like torchdata>0.5 in setup.py to make sure a proper dependency error is raised during installation.

0reactions
joecummingscommented, Dec 13, 2022

Closing this as resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting ImportError when using torchtext - Stack Overflow
from torchtext.legacy.data import Field, TabularDataset, ... I come up with this when using colab, then I update the torchtext version by
Read more >
ImportError while "from torchtext.datasets import ... - GitHub
Has any one encountered the same ImportError that cannot "from torchtext.datasets import text_classification"? Is it because of the version ...
Read more >
Cannot import name 'TranslationDataset' from 'torchtext.datasets'
I have installed pytorch correctly and can import torchtext.data and torchtext.datasets, but why can't I import TranslationDataset.
Read more >
cannot import name 'field' from 'torchtext.data' - You.com
My notebook suddenly throws import errors: "cannot import name 'Field' from 'torchtext.data' " About 2 weeks ago, it worked perfectly and I didn't...
Read more >
ImportError: cannot import name 'Field' from 'torchtext.data', No ...
torchtext 的那些事儿.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found