Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"no module named torch". But installed pytorch 1.3.0 with conda in Ubuntu 18.04.02 Server Edition

installed pytorch with conda :

(base) (3.8.0/envs/my_virtual_env-3.8.0) marco@pc:~/facenet_pytorch/examples$ conda install  
pytorch torchvision cpuonly -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

I updated conda:

(base) (3.8.0/envs/my_virtual_env-3.8.0) marco@pc:~/facenet_pytorch/examples$ conda update 
conda
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

Installed mkl=2019 :

(base) (3.8.0/envs/my_virtual_env-3.8.0) marco@pc:~/facenet_pytorch/examples$ conda install  
mkl=2019
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

(base) (3.8.0/envs/my_virtual_env-3.8.0) marco@pc:~/facenet_pytorch/examples$ conda list | grep 
torch
cpuonly                   1.0                           0    pytorch
facenet-pytorch           0.1.0                    pypi_0    pypi
pytorch                   1.3.0               py3.7_cpu_0  [cpuonly]  pytorch
torchfile                 0.1.0                    pypi_0    pypi
torchvision               0.4.1                  py37_cpu  [cpuonly]  pytorch

But it still says "no module torch" :

(base) (3.8.0/envs/my_virtual_env-3.8.0) marco@pc:~/facenet_pytorch/examples$ python3
Python 3.8.0 (default, Oct 30 2019, 16:20:23) 
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'
>>> 

I discovered that the problem appears only with python 3.8.0 version

(base) marco@pc:~/facenet_pytorch$ python3
Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> 

Ubuntu 18.04.02 Server Edition

Or, may be, it's just a matter of python environments, as you said. But I do not understand why just activating conda environment, with "conda activate", it doesn't work

Marco

like image 351
user2315094 Avatar asked Dec 09 '25 12:12

user2315094


1 Answers

First create a Conda environment using:

conda create -n pytorch_env python=3 ( you can create with any python version )

Activate the environment using:

conda activate pytorch_env

Now install PyTorch using:

conda install pytorch-cpu torchvision -c pytorch

Go to python shell and import using the command:

import torch
like image 198
srilekha palepu - Intel Avatar answered Dec 12 '25 02:12

srilekha palepu - Intel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!