Can't Import Pytorch

Can't Import Pytorch

I am trying to import pytorch but I get an error that module does not exist. I installed via anaconda, and the folder "pytorch-0.1.12-py35_2cu80" exist in anaconda3/pkgs folder. why does it not recognize that it is there? should I rename this folder?

-Rik

/home/rik/anaconda3/bin/python /home/rik/PycharmProjects/self_driving_car/self_driving.py
Traceback (most recent call last):
  File "/home/rik/PycharmProjects/self_driving_car/self_driving.py", line 18, in <module>
    import pytorch
ImportError: No module named 'pytorch'

Process finished with exit code 1
2

2 Answers

The command to import pytorch is

import torch

not

import pytorch

It seems the module pytorch is not installed.

First make sure your using anaconda's python and not the system one.

To install pytorch via conda do

conda install pytorch torchvision -c soumith

or via pip

For python3

pip install  
pip install torchvision

For python2

pip install  
pip install torchvision

dont install the CUDA version if you dont have Nvidia GPU on your machine that supports.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.