No module named torch

I am trying to run a python file that uses ‘import torch’ but I get the error

ModuleNotFoundError: No module named 'torch'

I tried uninstalling it and reinstalling it with pip and conda but nothing works, it is correctly installed but I still get the error

It seems that PyTorch wasn’t correctly installed in your current environment.
You can check it via conda env list | grep torch or the pip equivalent.

Hello,
Can you help me? I tried almost all that I could find on the web but still get an error message.

Basically, I created a new conda environment and installed pytorch in a computer cluster.
It seems correctly installed but I still get the error message "ModuleNotFoundError: No module named ‘torch.’

(env_pytorch) [asidasi@hpcc ~]$
(env_pytorch) [asidasi@hpcc ~]$ python -c “import torch”
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘torch’
(env_pytorch) [asidasi@hpcc ~]$
(env_pytorch) [asidasi@hpcc ~]$
(env_pytorch) [asidasi@hpcc ~]$ conda list | grep torch

packages in environment at /home/asidasi/.conda/envs/env_pytorch:

ffmpeg 4.3 hf484d3e_0 pytorch
pytorch 1.8.0 py3.6_cuda10.2_cudnn7.6.5_0 pytorch
torchaudio 0.8.0 py36 pytorch
torchvision 0.9.0 py36_cu102 pytorch
(env_pytorch) [asidasi@hpcc ~]$

Have you activated the conda environment? You might be running Python which defaults to pip?

Thanks for a quick reply!
Yes, I already activated my conda environment (env_pytorch), as you can see in my post.
I also double-checked which python I am using. I am using the correct python in my env.

can you check by typing “which python” in the terminal? That’ll tell what python executable it’s using. Also, if you’re submitting a job via a job scheduler it might be changing the environment post-launch. For example with PBS you need to state the environment at the beginning of your .py script.

I tried that, too. See below.

(env_pytorch) [asidasi@hpcc ~]$ which python
~/.conda/envs/env_pytorch/bin/python
(env_pytorch) [asidasi@hpcc ~]$ ~/.conda/envs/env_pytorch/bin/python -c “import torch”
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘torch’
(env_pytorch) [asidasi@hpcc ~]$