ImportError: ImportError: No module named torch.nn and No module named torchvision.transforms -


I have an old piece of code that I run on a virtual environment,

when I import torchvision.transforms in a python environment, it works fine, but when I run a python script that imports the same, from terminal, it gives this error:

ImportError: No module named torchvision.transforms

it was working fine before I switched to CUDA10.1 and then back to CUDA9.0 if that matters, but I don’t understand how it works just fine when I simply import in a python environment, but won’t work when I call a python script.

Same with torch.


Could you print the sys.executable in your Python environment and inside the script?
If you can run it in a REPL session, but not as a script, maybe you are not using the current Python install/environment.

1 Like

Thank you, you are right, for some reason the script doesn’t run on the venv I run it on. It prints


while in a session it prints the venv

import sys
print sys.executable

It seems to be related to user/root settings