I’m facing a strange issue given that suddenly, i can not anymore import torchvision.
I removed and installed pytorch + torchvision but it did not help.
>>> import torchvision
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/renaud/anaconda3/envs/tfe/lib/python3.6/site-packages/torchvision/__init__.py", line 3, in <module>
from torchvision import models
File "/home/renaud/anaconda3/envs/tfe/lib/python3.6/site-packages/torchvision/models/__init__.py", line 5, in <module>
from .inception import *
File "/home/renaud/anaconda3/envs/tfe/lib/python3.6/site-packages/torchvision/models/inception.py", line 6, in <module>
from torch.jit.annotations import Optional
ImportError: cannot import name 'Optional'
It seems that the installed PyTorch and torchvision versions are not compatible.
I guess that torchvision might be in a newer version and tries to call torch.jit.annotations.Optional, which isn’t available in your (older) PyTorch installation.
My torch version is 1.0.0 and in my conda env: 1.5.0
I can not print torchvision.__version__ given that I can not even import it, but the version in my conda env is 0.6.0.
As I mentionned, everything worked fine until this bug appeared. I always work in different conda env but is it possible that creating a new env with an older version of pytorch has produced this error ?
These failures all point to a torch version, which is too old, as both methods are relatively new.
I just reinstalled PyTorch 1.5.0 with torchvision0.6.0 and am able to import both libs as well as import torch.jit.annotations.Optional.
Could you check the path of torch via: print(torch.__path__) and make sure that it’s pointing to the right environment folder?
This is working when i’m in the folder in anaconda that contains torchvision.
But i don’t know how to change the sys.path in python such that it import my packages from anaconda/envs/....
By the way I also don’t know why it has changed.
Thank you for you help!
Do you have a hint how I can change the path used for loading those packages ?