Installing pytorch on a machine without GPU

Vishal_Ahuja: <p>So, I installed pytorch using the following command:<br>
<code>conda install pytorch-cpu==1.0.0 torchvision-cpu==0.2.1 cpuonly -c pytorch</code></p>
<p>The following works:<br>
<code>import torch</code><br>
<code>x = torch.rand(5, 3)</code><br>
<code>print(x)</code></p>
<p>But<br>
<code>import torchvision</code></p>
<p>fails with the error  <code>ImportError: libcudart.so.10.0: cannot open shared object file: No such file or directory</code></p>
<p>What am I missing?</p>

ptrblck: <p>Could you post the log from the installation please?<br>
Also, PyTorch <code>1.0.0</code> and torchvision <code>0.2.1</code> are quite old by now so you might want to install the latest stable releases.</p>

Vishal_Ahuja: <p>Okay, so I created a new conda environment like this:<br>
<code>conda create -n dl1 python=3.6 </code></p>
<p>Then, I activated the environment created above and ran the command to install the latest version:</p>
<p><code>conda install pytorch torchvision cpuonly -c pytorch</code></p>
<p>After that, at the <code>python</code> prompt:</p>
<pre><code class="lang-auto">&gt;&gt;&gt; import torchvision

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

ptrblck: <p>Could you print the installation log you are getting, please?<br>
I just installed it locally and can see that the CPU version is being installed.</p>

Vishal_Ahuja: <p>Here it is</p>
<pre><code class="lang-auto">(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


==&gt; WARNING: A newer version of conda exists. &lt;==
  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

</code></pre>

Vishal_Ahuja: <p>Can someone please guide me here?</p>

raj-rishav: <p>Hello Vishal, I believe that Python Prompt in which you tried to run the command<br>
<code>import torchvision</code> is NOT inside the conda environment.</p>
<p>You see if it was inside the conda environment it was supposed to look in <code>/home/iseadmin/anaconda3/envs/dl1/lib/python3.6/site-packages/torchvision</code></p>
<p>So run the following commands in a sequence and let me know the result:<br>
<code>conda activate dl1</code><br>
<code>python3</code> and then try to import</p>
<p>Let me know if it works or not.</p>

Stephany_Berrio: <p>How did you solve this issue?  I’m stuck here:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/d/4d6416da0e58aaecf9fd654f8d9abb25414c2cfc.png" data-download-href="https://discuss.pytorch.org/uploads/default/4d6416da0e58aaecf9fd654f8d9abb25414c2cfc" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/d/4d6416da0e58aaecf9fd654f8d9abb25414c2cfc_2_600x500.png" alt="image" data-base62-sha1="b2DcJSUK0ZISEKvKyuj55pnhcWU" width="600" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/d/4d6416da0e58aaecf9fd654f8d9abb25414c2cfc_2_600x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/4/d/4d6416da0e58aaecf9fd654f8d9abb25414c2cfc_2_900x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/4/d/4d6416da0e58aaecf9fd654f8d9abb25414c2cfc.png 2x" data-dominant-color="080808"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1061×883 132 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>Do you have any other <code>torchvision</code> or PyTorch installations on this machine and environment?<br>
I just tried to reproduce the import issue by installing PyTorch <code>1.7.0</code> and <code>torchvision==0.8.1</code> as the CPU-only packages in a new conda env via:</p>
<pre><code class="lang-auto">conda install pytorch torchvision torchaudio cpuonly -c pytorch
</code></pre>
<p>and I can <code>import torchvision</code>:</p>
<pre><code class="lang-python">&gt;&gt;&gt; import torch
&gt;&gt;&gt; torch.__version__
'1.7.0'
&gt;&gt;&gt; import torchvision
&gt;&gt;&gt; torchvision.__version__
'0.8.1'
</code></pre>

Stephany_Berrio: <p>Yes, that was the problem, I thought <code>conda</code> prioritizes the environment packages over the local ones. Seems that’s not the case, so I just uninstall the local<code> torchvision</code> and it worked!.</p>
<p>Thanks!</p>