Installing pytorch on a machine without GPU

So, I installed pytorch using the following command:
conda install pytorch-cpu==1.0.0 torchvision-cpu==0.2.1 cpuonly -c pytorch

The following works:
import torch
x = torch.rand(5, 3)
print(x)

But
import torchvision

fails with the error ImportError: libcudart.so.10.0: cannot open shared object file: No such file or directory

What am I missing?

Could you post the log from the installation please?
Also, PyTorch 1.0.0 and torchvision 0.2.1 are quite old by now so you might want to install the latest stable releases.

Okay, so I created a new conda environment like this:
conda create -n dl1 python=3.6

Then, I activated the environment created above and ran the command to install the latest version:

conda install pytorch torchvision cpuonly -c pytorch

After that, at the python prompt:

>>> import torchvision

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/iseadmin/.local/lib/python3.6/site-packages/torchvision/__init__.py", line 1, in <module>
    from torchvision import models
  File "/home/iseadmin/.local/lib/python3.6/site-packages/torchvision/models/__init__.py", line 11, in <module>
    from . import detection
  File "/home/iseadmin/.local/lib/python3.6/site-packages/torchvision/models/detection/__init__.py", line 1, in <module>
    from .faster_rcnn import *
  File "/home/iseadmin/.local/lib/python3.6/site-packages/torchvision/models/detection/faster_rcnn.py", line 7, in <module>
    from torchvision.ops import misc as misc_nn_ops
  File "/home/iseadmin/.local/lib/python3.6/site-packages/torchvision/ops/__init__.py", line 1, in <module>
    from .boxes import nms, box_iou
  File "/home/iseadmin/.local/lib/python3.6/site-packages/torchvision/ops/boxes.py", line 2, in <module>
    from torchvision import _C
ImportError: libcudart.so.10.0: cannot open shared object file: No such file or directory

Could you print the installation log you are getting, please?
I just installed it locally and can see that the CPU version is being installed.

Here it is

(dl1) iseadmin@iseadmin:~/Downloads/trucks/course-v3/nbs/dl1$ conda install pytorch torchvision cpuonly -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.7.11
  latest version: 4.8.2

Please update conda by running

    $ conda update -n base conda



## Package Plan ##

  environment location: /home/iseadmin/anaconda3/envs/dl1

  added / updated specs:
    - cpuonly
    - pytorch
    - torchvision


The following NEW packages will be INSTALLED:

  cpuonly            pytorch/noarch::cpuonly-1.0-0
  freetype           conda-forge/linux-64::freetype-2.10.0-he983fc9_1
  intel-openmp       pkgs/main/linux-64::intel-openmp-2020.0-166
  jpeg               conda-forge/linux-64::jpeg-9c-h14c3975_1001
  libblas            conda-forge/linux-64::libblas-3.8.0-14_openblas
  libcblas           conda-forge/linux-64::libcblas-3.8.0-14_openblas
  libgfortran-ng     conda-forge/linux-64::libgfortran-ng-7.3.0-hdf63c60_5
  liblapack          conda-forge/linux-64::liblapack-3.8.0-14_openblas
  libopenblas        conda-forge/linux-64::libopenblas-0.3.7-h5ec1e0e_6
  libpng             conda-forge/linux-64::libpng-1.6.37-hed695b0_0
  libtiff            conda-forge/linux-64::libtiff-4.1.0-hc3755c2_3
  lz4-c              conda-forge/linux-64::lz4-c-1.8.3-he1b5a44_1001
  mkl                pkgs/main/linux-64::mkl-2020.0-166
  ninja              conda-forge/linux-64::ninja-1.10.0-hc9558a2_0
  numpy              conda-forge/linux-64::numpy-1.18.1-py36h95a1406_0
  olefile            conda-forge/noarch::olefile-0.46-py_0
  pillow             conda-forge/linux-64::pillow-7.0.0-py36hefe7db6_0
  pytorch            pytorch/linux-64::pytorch-1.4.0-py3.6_cpu_0
  six                conda-forge/linux-64::six-1.14.0-py36_0
  torchvision        pytorch/linux-64::torchvision-0.5.0-py36_cpu
  zstd               conda-forge/linux-64::zstd-1.4.4-h3b9ef0a_1


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Can someone please guide me here?

Hello Vishal, I believe that Python Prompt in which you tried to run the command
import torchvision is NOT inside the conda environment.

You see if it was inside the conda environment it was supposed to look in /home/iseadmin/anaconda3/envs/dl1/lib/python3.6/site-packages/torchvision

So run the following commands in a sequence and let me know the result:
conda activate dl1
python3 and then try to import

Let me know if it works or not.

How did you solve this issue? I’m stuck here:

Do you have any other torchvision or PyTorch installations on this machine and environment?
I just tried to reproduce the import issue by installing PyTorch 1.7.0 and torchvision==0.8.1 as the CPU-only packages in a new conda env via:

conda install pytorch torchvision torchaudio cpuonly -c pytorch

and I can import torchvision:

>>> import torch
>>> torch.__version__
'1.7.0'
>>> import torchvision
>>> torchvision.__version__
'0.8.1'
1 Like

Yes, that was the problem, I thought conda prioritizes the environment packages over the local ones. Seems that’s not the case, so I just uninstall the local torchvision and it worked!.

Thanks!

1 Like