DataLoader : TypeError: Instance and class checks can only be used with @runtime_checkable protocols

promach: <p>Why the error with <code>DataLoader</code> when I upgrade from python version 3.9 to 3.10 ?</p>
<p>I added <code>@runtime_checkable</code> just before <a href="https://github.com/pytorch/pytorch/blob/master/torch/utils/data/dataloader.py#L75" rel="noopener nofollow ugc">DataLoader class</a>, but it does not help with <code>NameError: name 'runtime_checkable' is not defined</code></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/7/674b26e14892202dc8aef76b33dc88187639a2e0.png" data-download-href="https://discuss.pytorch.org/uploads/default/674b26e14892202dc8aef76b33dc88187639a2e0" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/674b26e14892202dc8aef76b33dc88187639a2e0_2_466x500.png" alt="image" data-base62-sha1="eJMbSx4ffUziLApmWxCSdOgbgJi" width="466" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/674b26e14892202dc8aef76b33dc88187639a2e0_2_466x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/674b26e14892202dc8aef76b33dc88187639a2e0_2_699x750.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/674b26e14892202dc8aef76b33dc88187639a2e0_2_932x1000.png 2x" data-dominant-color="373839"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">980×1050 139 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

nivek: <p>Based on the <a href="https://docs.python.org/3/library/typing.html#typing.runtime_checkable" rel="noopener nofollow ugc">official Python documentation about @runtime_checkable</a>, the decorator should only be applied on a <code>Protocol</code> class. Since DataLoader is not, it will raise the <code>TypeError</code> that you are seeing if you add <code>@runtime_checkable</code> just before the DataLoader class.</p>

nivek: <p>We also landed a new PR that allows subclasses of <code>IterableDataset</code> to be used in <code>DataLoader</code> with Python 3.10. If you download the nightly version of PyTorch from <a href="https://pytorch.org/" rel="noopener nofollow ugc">the middle of this page</a>, it should work.</p>

promach: <p>Is there a way to get around this error without installing the nightly version of Pytorch ?</p>

nivek: <p>I don’t think it is possible at the moment. We are still working on Python 3.10 support. You can track the issue here:</p><aside class="onebox githubissue" data-onebox-src="https://github.com/pytorch/pytorch/issues/66424">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/issues/66424" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/pytorch</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewbox="0 0 14 16" aria-hidden="true"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/pytorch/issues/66424" target="_blank" rel="noopener nofollow ugc">Add Python-3.10 support</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2021-10-11" data-time="14:50:39" data-timezone="UTC">02:50PM - 11 Oct 21 UTC</span>
      </div>


      <div class="user">
        <a href="https://github.com/malfet" target="_blank" rel="noopener nofollow ugc">
          <img alt="malfet" src="https://avatars.githubusercontent.com/u/2453524?v=4" class="onebox-avatar-inline" width="20" height="20">
          malfet
        </a>
      </div>
    </div>

    <div class="labels">
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          high priority
        </span>
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          module: ci
        </span>
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          triaged
        </span>
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          enhancement
        </span>
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">Python 3.10 has been released on Oct-4th, i.e. we should add support for it in n<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">ightlies

cc @ezyang @gchanan @zou3519 @bdhirsh @jbschlosser @seemethere @malfet @pytorch/pytorch-dev-infra</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


promach: <p>I have used the <a href="https://archlinux.org/packages/community/x86_64/python-pytorch-cuda/" rel="noopener nofollow ugc">compiled binary on 25 December</a>, but I am still getting the same error.</p>
<p>Did I miss anything ?</p>

nivek: <p>I do not believe that is the nightly version and hence it may not have the latest changes.</p>
<p>Please use the nightly version linked <a href="https://pytorch.org/" rel="noopener nofollow ugc">here</a>.</p>

James_Johnson: <p>Hi, I am facing the same error. Did you come across any solution ?. If so, please help me.</p>

promach: <p>you can use virtual environment inside PyCharm, but make sure you need to install Python3.9 in your OS system</p>
<p>Python version upgrade from 3.9 to 3.10 is what causing the issue.</p>

ejguan: <p>Either use python 3.9 for now before next PyTorch release, or use the master branch of PyTorch to compile your code. A patch to fix it has landed.</p>