Import torchvision error - TypeError: _resolve_type_from_object(): incompatible function arguments

username: desmond13
cooked: <p>Hi, I am trying to run the following import instructions in a jupyter notebook but torchvision is giving me a problem</p>
<pre><code class="lang-auto">from __future__ import print_function, division 
! python --version 
! python2 --version 
! python3 --version 
import os 
import torch 
import pandas as pd 
from skimage import io, transform 
import numpy as np 
import matplotlib.pyplot as plt 
from torch.utils.data import Dataset, DataLoader 
import sys 
print(sys.version) 
import torchvision
# from torchvision import transforms, utils
</code></pre>
<p>The output is the following</p>
<pre><code class="lang-auto">Python 3.5.2
Python 2.7.12
Python 3.5.2
3.5.2 (default, Apr 16 2020, 17:47:17) 
[GCC 5.4.0 20160609]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-1-3a8a37d1acbb&gt; in &lt;module&gt;
     12 import sys
     13 print(sys.version)
---&gt; 14 import torchvision
     15 # from torchvision import transforms, utils

~/virtualenvs/testenv1/lib/python3.5/site-packages/torchvision/__init__.py in &lt;module&gt;
      1 import warnings
      2 
----&gt; 3 from torchvision import models
      4 from torchvision import datasets
      5 from torchvision import ops

~/virtualenvs/testenv1/lib/python3.5/site-packages/torchvision/models/__init__.py in &lt;module&gt;
     10 from .shufflenetv2 import *
     11 from . import segmentation
---&gt; 12 from . import detection
     13 from . import video
     14 from . import quantization

~/virtualenvs/testenv1/lib/python3.5/site-packages/torchvision/models/detection/__init__.py in &lt;module&gt;
----&gt; 1 from .faster_rcnn import *
      2 from .mask_rcnn import *
      3 from .keypoint_rcnn import *

~/virtualenvs/testenv1/lib/python3.5/site-packages/torchvision/models/detection/faster_rcnn.py in &lt;module&gt;
     12 from .generalized_rcnn import GeneralizedRCNN
     13 from .rpn import AnchorGenerator, RPNHead, RegionProposalNetwork
---&gt; 14 from .roi_heads import RoIHeads
     15 from .transform import GeneralizedRCNNTransform
     16 from .backbone_utils import resnet_fpn_backbone

~/virtualenvs/testenv1/lib/python3.5/site-packages/torchvision/models/detection/roi_heads.py in &lt;module&gt;
    208 
    209 
--&gt; 210 @torch.jit.script
    211 def _onnx_heatmaps_to_keypoints_loop(maps, rois, widths_ceil, heights_ceil,
    212                                      widths, heights, offset_x, offset_y, num_keypoints):

~/virtualenvs/testenv1/lib/python3.5/site-packages/torch/jit/__init__.py in script(obj, optimize, _frames_up, _rcb)
   1288         if _rcb is None:
   1289             _rcb = _jit_internal.createResolutionCallbackFromClosure(obj)
-&gt; 1290         fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
   1291         # Forward docstrings
   1292         fn.__doc__ = obj.__doc__

~/virtualenvs/testenv1/lib/python3.5/site-packages/torch/jit/_recursive.py in try_compile_fn(fn, loc)
    566     # object
    567     rcb = _jit_internal.createResolutionCallbackFromClosure(fn)
--&gt; 568     return torch.jit.script(fn, _rcb=rcb)
    569 
    570 def wrap_cpp_module(cpp_module):

~/virtualenvs/testenv1/lib/python3.5/site-packages/torch/jit/__init__.py in script(obj, optimize, _frames_up, _rcb)
   1288         if _rcb is None:
   1289             _rcb = _jit_internal.createResolutionCallbackFromClosure(obj)
-&gt; 1290         fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
   1291         # Forward docstrings
   1292         fn.__doc__ = obj.__doc__

~/virtualenvs/testenv1/lib/python3.5/site-packages/torch/jit/__init__.py in _get_overloads(obj)
   2028     compiled_fns = []
   2029     for overload_fn in uncompiled_overloads:
-&gt; 2030         compiled_fns.append(_compile_function_with_overload(overload_fn, qual_name, obj))
   2031 
   2032     if existing_compiled_fns:

~/virtualenvs/testenv1/lib/python3.5/site-packages/torch/jit/__init__.py in _compile_function_with_overload(overload_fn, qual_name, impl_fn)
   2008 def _compile_function_with_overload(overload_fn, qual_name, impl_fn):
   2009     overload_decl = torch.jit.get_jit_def(overload_fn).decl()
-&gt; 2010     overload_signature = torch.jit.annotations.get_signature(overload_fn, None, None, inspect.ismethod(overload_fn))
   2011     impl_ast = torch.jit.get_jit_def(impl_fn)
   2012     overload_defaults = get_default_args(overload_fn)

~/virtualenvs/testenv1/lib/python3.5/site-packages/torch/jit/annotations.py in get_signature(fn, rcb, loc, is_method)
     77         # because it didn't have any annotations.
     78         if type_line is not None:
---&gt; 79             signature = parse_type_line(type_line, rcb, loc)
     80 
     81     return signature

~/virtualenvs/testenv1/lib/python3.5/site-packages/torch/jit/annotations.py in parse_type_line(type_line, rcb, loc)
    163         raise RuntimeError("Failed to parse the return type of a type annotation: {}".format(str(e)))
    164 
--&gt; 165     arg_types = [ann_to_type(ann, loc) for ann in arg_ann]
    166     return arg_types, ann_to_type(ret_ann, loc)
    167 

~/virtualenvs/testenv1/lib/python3.5/site-packages/torch/jit/annotations.py in &lt;listcomp&gt;(.0)
    163         raise RuntimeError("Failed to parse the return type of a type annotation: {}".format(str(e)))
    164 
--&gt; 165     arg_types = [ann_to_type(ann, loc) for ann in arg_ann]
    166     return arg_types, ann_to_type(ret_ann, loc)
    167 

~/virtualenvs/testenv1/lib/python3.5/site-packages/torch/jit/annotations.py in ann_to_type(ann, loc)
    301 
    302 def ann_to_type(ann, loc):
--&gt; 303     the_type = try_ann_to_type(ann, loc)
    304     if the_type is not None:
    305         return the_type

~/virtualenvs/testenv1/lib/python3.5/site-packages/torch/jit/annotations.py in try_ann_to_type(ann, loc)
    294         def fake_rcb(key):
    295             return None
--&gt; 296         the_type = torch._C._resolve_type_from_object(ann, loc, fake_rcb)
    297         if the_type is not None:
    298             return the_type

TypeError: _resolve_type_from_object(): incompatible function arguments. The following argument types are supported:
    1. (arg0: object, arg1: torch._C._jit_tree_views.SourceRange, arg2: Callable[[str], function]) -&gt; torch._C.Type

Invoked with: typing.Union[int, NoneType], None, &lt;function try_ann_to_type.&lt;locals&gt;.fake_rcb at 0x7f8aa1ad2e18&gt;

</code></pre>
<p>I tried to search on the internet but I could not find anything. Any ideas on how to solve this problem?</p>
<p>Thanks!</p>

username: desmond13
cooked: <p>I actually found only now this issue that seems exactly the same one I am facing:<br>
<aside class="onebox githubissue">
  <header class="source">
      <a href="https://github.com/pytorch/vision/issues/2132" target="_blank" rel="nofollow noopener">github.com/pytorch/vision</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/vision/issues/2132" target="_blank" rel="nofollow noopener">Torchvision 0.6.0 doesn't work on Ubuntu 16.04.3 with Python 3.5.2</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2020-04-23" data-time="00:00:01" data-timezone="UTC">12:00AM - 23 Apr 20 UTC</span>
      </div>


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

<div class="github-row">
  <p class="github-content">🐛 Bug
To Reproduce
Steps to reproduce the behavior:
Create a virtual environment
python -m venv venv
Activate the virtual environment
pip install torchvision
Run the following line:
import...</p>
</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;">bug</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">help wanted</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">needs reproduction</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">topic: binaries</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">torchscript</span>
</div>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>