close

[Fixed] ModuleNotFoundError: No module named ‘torch’

Today We are Going To Solve ModuleNotFoundError: No module named ‘torch’ in Python. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

How to Fix ModuleNotFoundError: No module named ‘torch’ Error?

  1. How to Fix ModuleNotFoundError: No module named ‘torch’ Error?

    To Fix ModuleNotFoundError: No module named ‘torch’ Error just For anaconda prompt users. If you are using Anaconda Prompt, then this is the best solution for you. Just try the below command to solve your error. conda install -c pytorch pytorch

  2. ModuleNotFoundError: No module named ‘torch’

    To Fix ModuleNotFoundError: No module named ‘torch’ Error just Try this commands. To solve this error just add the below one at the very top of your program import torch And try this. import sys print(sys.executable)

Solution 1 : For anaconda prompt users

If you are using Anaconda Prompt, then this is the best solution for you. Just try the below command to solve your error.

conda install -c pytorch pytorch

Solution 2 : Try this commands

To solve this error just add the below one at the very top of your program

import torch

And try this.

import sys
print(sys.executable)

Solution 3 : install PyTorch using pip

You can solve this error by installing PyTorch using pip:

First of all, create a Conda environment using the below command:

conda create -n env_pytorch python=3.6

Then just activate the environment using by below command:

conda activate env_pytorch

And install PyTorch using pip

pip install torchvision 

And at the end just go to Python shell and import these two:

import torch
import torchvision

And your error will be solved.

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read This Solutions

Leave a Comment