gokulsrin
gokulsrin

Reputation: 341

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

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.

Upvotes: 31

Views: 70234

Answers (4)

Sudhanthiran Ganesan
Sudhanthiran Ganesan

Reputation: 61

This command works

pip3 install torch torchvision torchaudio

from https://pytorch.org/get-started/locally/#anaconda

Upvotes: 6

Ahmad
Ahmad

Reputation: 1845

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

Upvotes: 18

Matt Popovich
Matt Popovich

Reputation: 240

The issue for me was that, despite making and building torchvision... there is an additional step to install it!

To build the C++ API from source (optional):

cd /location/to/vision
mkdir build && cd build
# Add -DWITH_CUDA=on to the below cmake command to build with support for CUDA
# Also add -DTorch_DIR=/path/to/Torch/ if necessary
cmake ..
make
make install

And then to install torchvision from source:

cd /location/to/vision
python setup.py install

This is assuming you clone torchvision to /location/to/vision:

cd /location/to
git clone https://github.com/pytorch/vision.git

Upvotes: 1

alfred Shen
alfred Shen

Reputation: 21

Reinstall jupyter notekook after pytorch installation worked for me.

conda install -c conda-forge notebook 

Upvotes: 2

Related Questions