Having trouble importing PyTorch


I’m having a rather unusual problem importing PyTorch. I use VirtualBox 6.1 and Ubuntu 20.4 to run my ROS application with PyTorch as backend. Since yesterday I have the following error when I want to train my neural network. It worked a couple of weeks ago and I haven’t changed the code sind then. the only thing changed was the PyTorch 1.9.0 release.

Traceback (most recent call last):
  File "/home/marta/catkin_ws/src/imagineer/src/ai_service/ai_service.py", line 2, in <module>
    import torch, os, numpy
ImportError: No module named torch

But PyTorch is definitely installed I tested it with:

Python 3.8.5 (default, May 27 2021, 13:30:53) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
>>> torch.cuda.is_available()

I already deleted my catkin_ws Workspace, deleted and reinstalled ROS, reinstalled PyTorch 1.9.0 and 1.8.0 (current version now is 1.8.0) but the error message remains. Any idea where the problem could be?

Are you using a different conda/pip environment or a different python (e.g. launched via sudo python)?

No, I haven’t touched my VirtualBox since I had a working application.