Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Despite installing the torch vision pytorch library, I am getting an error saying that there is no module named torch vision

Tags:

python

pytorch

The error that I am getting when I use import torchvision is this:

Error Message

"*Traceback (most recent call last):
  File "/Users/gokulsrin/Desktop/torch_basics/data.py", line 4, in <module>
    import torchvision
ModuleNotFoundError: No module named 'torchvision'*"

I don't know what to do. I have tried changing the version of python from the native one to the one downloaded through anaconda. I am using anaconda as a package manager and have installed torch vision through anaconda as well as through pip commands.

like image 778
gokulsrin Avatar asked Jan 07 '20 03:01

gokulsrin


People also ask

How do you solve Modulenotfounderror No module named torch?

Solution 1: Using pip to install pytorch – Here is the pip command to install PyTorch. The above command will install the latest version of the PyTorch module. You can specify any other version with the same command. Now if you are using python 3 then specifically we can use pip3 in the above command.

How do I install Python torch library?

To install PyTorch, you have to run the installation command of PyTorch on your command prompt. This command is available on https://pytorch.org/. Select language and cuda version as per your requirement. Now, run python -version, and Conda -version command to check Conda and python packages are installed or not.

Is Torchvision same as PyTorch?

This library is part of the PyTorch project. PyTorch is an open source machine learning framework.


1 Answers

From PyTorch installing Docs you should follow these steps:

  • In Anaconda use this command:
    conda install pytorch torchvision cpuonly -c pytorch

  • In Pip use this command:
    pip3 install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html

Note: If you have an enabled CUDA card you can change the cpuonly option to cudatoolkit=10.1 or cudatoolkit=9.2

After successfully installing the package you can import it with the command import torchvision and the output should look like this: enter image description here

Otherwise, there is something wrong when you are downloading the package from the Internet

like image 73
Ahmad Avatar answered Sep 23 '22 14:09

Ahmad