Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install Pytorch 1.3.1 with CUDA enabled

I have a conda environment on my Ubuntu 16.04 system.

When I install Pytorch using:

conda install pytorch

and I try and run the script I need, I get the error message:

raise AssertionError("Torch not compiled with CUDA enabled")

From looking at forums, I see that this is because I have installed Pytorch without CUDA support.

I then tried:

conda install -c pytorch torchvision cudatoolkit=10.1 pytorch

but now I get the error:

    from torch.utils.cpp_extension import BuildExtension, CUDAExtension
  File "/home/username/miniconda3/envs/super_resolution/lib/python3.6/site-packages/torch/__init__.py", line 81, in <module>
    from torch._C import *
ImportError: /lib64/libc.so.6: version `GLIBC_2.14' not found

So it seems that these two installs are installing different versions of Pytorch(?). The first one that seemed to work was Pytorch 1.3.1.

My question: How do I install Pytorch with CUDA enabled, but ensure it is version 1.3.1 so that it works with my system?

like image 870
user1551817 Avatar asked Aug 31 '25 02:08

user1551817


2 Answers

Given that your system is running Ubuntu 16.04, it comes with glibc installed. You can check your version by typing ldd --version.

Keep in mind that PyTorch is compiled on CentOS which runs glibc version 2.17.

Then check the CUDA version installed on your system nvcc --version

Then install PyTorch as follows e.g. if your cuda version is 9.2: conda install pytorch torchvision cudatoolkit=9.2 -c pytorch

If you get the glibc version error, try installing an earlier version of PyTorch.

If neither of the above options work, then try installing PyTorch from sources.

If you would like to set a specific PyTorch version to install, please set it as <version_nr> in the below command: conda install pytorch=<version_nr> torchvision cudatoolkit=9.2 -c pytorch

like image 181
avgJoe Avatar answered Sep 02 '25 14:09

avgJoe


For CUDA 10.1:

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

For CUDA 9.2:

conda install pytorch torchvision cudatoolkit=9.2 -c pytorch

For no CUDA:

conda install pytorch torchvision cpuonly -c pytorch
like image 42
Manas Satti Avatar answered Sep 02 '25 15:09

Manas Satti