4

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?

talonmies
  • 70,661
  • 34
  • 192
  • 269
user1551817
  • 6,693
  • 22
  • 72
  • 109
  • 1
    What is your cuda version? Did you try with `9.0` or `10.0`? What is your OS? – Szymon Maszke Jan 02 '20 at 18:26
  • My OS is Ubuntu 16.04. With either cuda 8.0 or 10.0 I get the same error message. – user1551817 Jan 03 '20 at 13:26
  • 1
    @SzymonMaszke do you need to install CUDA on your OS in order to use it with `conda + Pytorch ` ? Yesterday I've heared that Pytorch conda installation comes with it's own CUDA. – sebastian-sz Jan 03 '20 at 14:20
  • Yes, you need CUDA capable device and cuda drivers installed. – Szymon Maszke Jan 03 '20 at 23:06
  • 2
    Have you tried with `conda install pytorch torchvision cudatoolkit=9.2 -c pytorch`? – Yamaneko Jan 05 '20 at 03:20
  • Thank you. I just tried to do that, but I still got the same `GLIBC_2.14' not found message. – user1551817 Jan 05 '20 at 12:50
  • 1
    @user1551817 can you post the output of `apt policy libc6`? – Yamaneko Jan 05 '20 at 16:52
  • hmmm it said "apt: invalid flag: policy" – user1551817 Jan 05 '20 at 19:01
  • 1
    @user1551817 Try an `apt-cache search libc` and see which versions are available. I'd suggest to install from there, but if it isn't available, I think you could try to install from this channel: `conda install -c pwwang glibc214 `. – Yamaneko Jan 05 '20 at 19:35
  • 1
    @user1551817 did any of these options work? – Yamaneko Jan 07 '20 at 00:06
  • Thank you for your suggestions. For `apt-cache search libc` I just get `-bash: apt-cache: command not found`. I am able to do the conda install, but then I still get the original message about `GLIBC_2.14 not found`. – user1551817 Jan 07 '20 at 11:49
  • 1
    What's the version of `glibc` on your machine (`ldd --version`)? You'll probably have to upgrade the _system_ glibc version _(upgrading conda env's `glibc` won't probably work)_, something like `apt-get install libc6` – kHarshit Jan 07 '20 at 13:12
  • When I try that I just get `-bash: apt-get: command not found`. I am not the root user, I don't know if that is relevant. – user1551817 Jan 07 '20 at 15:08
  • 1
    You need to be the root user or in the sudoers list (to use `sudo`) to upgrade the system library. You may look at [this answer](https://askubuntu.com/questions/491374/terminal-sudo-apt-get-command-not-found) for this error. – kHarshit Jan 07 '20 at 15:42
  • Okay thank you. Well I cannot use sudo on this system so it appears I will not be able to get Pytorch working? I was originally told that I would be okay with a different version of Pytorch that would be compatible for my system: https://stackoverflow.com/questions/59545197/can-i-fix-a-version-glibc-2-14-not-found-error-without-being-sysadmin – user1551817 Jan 07 '20 at 16:23
  • 1
    It seems pytorch's precompiled binary [expects that `glibc`](https://github.com/pytorch/pytorch/issues/6607#issuecomment-381423063). You may try installing [older versions of pytorch](https://pytorch.org/get-started/previous-versions/), but I'm not sure it'll work. Also, run [this script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py) to understand more about your env. – kHarshit Jan 07 '20 at 16:52
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/205542/discussion-between-user1551817-and-kharshit). – user1551817 Jan 07 '20 at 16:55

3 Answers3

5

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

avgJoe
  • 832
  • 7
  • 24
4

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
The Matt
  • 1,423
  • 1
  • 12
  • 22
1

Not sure whether you have solved your problem or not, but I have this exact same problem before because I was trying to install pytorch on a cluster and I don't have root access. You need to download glibc into your directoryand set the environmental variable LD_LIBRARY_PATH to your local glibc https://stackoverflow.com/a/48650638/5662642.

To install glibc locally, I will point you to this thread that I read to solve my problem

https://stackoverflow.com/a/38317265/5662642 (instead of setting --prefix=/opt/glibc-2.14 when installing, you might want to set it to other directory that you have access to). Hope it works for you