Unable to Import Torchvision --Attributeerror: Module 'Torch. Jit' Has No Attribute 'Unused'. Windows10, Python 3.7
I Am Trying to Import Torchvision but I Am Getting an Error. I Researched the Topic in the Web and There Seems to Be a Problem with the Later Versions...
I am trying to import torchvision but I am getting an error. I researched the topic in the Web and there seems to be a problem with the later versions. Different solutions were offered --mostly reinstalling the modules-- which I tried without a result The latest advice I found was to install torch and torchvision using the following command which I did successfully:
pip install torch===1.4.0 torchvision===0.5.0 -f
Still, the error persists:
(tf2) C:\Users\Alienware>python
Python 3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 22:22:21) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import torchvision
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Alienware\Anaconda3\envs\tf2\lib\site-packages\torchvision\__init__.py", line 3, in <module>
from torchvision import models
File "C:\Users\Alienware\Anaconda3\envs\tf2\lib\site-packages\torchvision\models\__init__.py", line 5, in <module>
from .inception import *
File "C:\Users\Alienware\Anaconda3\envs\tf2\lib\site-packages\torchvision\models\inception.py", line 65, in <module>
class Inception3(nn.Module):
File "C:\Users\Alienware\Anaconda3\envs\tf2\lib\site-packages\torchvision\models\inception.py", line 182, in Inception3
@torch.jit.unused
AttributeError: module 'torch.jit' has no attribute 'unused'
I am running Windows10, Anaconda 3, Python 3.7. My PC has a GPU and I have installed CUDA which works with TensorFlow and PyTorch.
4 Answers
For me downgrading torchvision to 0.4.0 did the trick:
pip uninstall torchvision
pip install torchvision==0.4.0 -f
I was able to import torchvision in an Environment ruining Python 3.6. It was impossible to run it with Python 3.7.
I am able to get this to run with the following commands:
conda create --name test5 python=3.6
conda install -c pytorch pytorch torchvision cpuonly
python
>>> import torch
>>> import torchvision
tl;dr pip3 install torchvision to upgrade torch and torchvision to latest compatible versions.
torchvision 0.7 has been released and is compatible with torch 1.6. It does not appear to be compatible with torch 1.5.
Note that installing torchvision via PyCharm may not result in an automatic upgrade of torch. Installing via pip3 did automatically upgrade torch however.