简体   繁体   English

如何在启用 CUDA 的情况下安装 Pytorch 1.3.1

[英]How do I install Pytorch 1.3.1 with CUDA enabled

I have a conda environment on my Ubuntu 16.04 system.我的 Ubuntu 16.04 系统上有一个 conda 环境。

When I install Pytorch using:当我使用以下方法安装 Pytorch 时:

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.从论坛上看,我看到这是因为我安装了没有 CUDA 支持的 Pytorch。

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(?).所以看起来这两个安装正在安装不同版本的 Pytorch(?)。 The first one that seemed to work was Pytorch 1.3.1.第一个似乎有效的是 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?我的问题:如何在启用 CUDA 的情况下安装 Pytorch,但要确保它是1.3.1版,以便它适用于我的系统?

Given that your system is running Ubuntu 16.04, it comes with glibc installed.鉴于您的系统运行的是 Ubuntu 16.04,它安装了 glibc。 You can check your version by typing ldd --version .您可以通过键入ldd --version来检查您的版本。

Keep in mind that PyTorch is compiled on CentOS which runs glibc version 2.17.请记住, PyTorch 是运行 glibc 2.17 版的 CentOS 上编译的

Then check the CUDA version installed on your system nvcc --version然后检查系统上安装的CUDA 版本nvcc --version

Then install PyTorch as follows eg if your cuda version is 9.2: conda install pytorch torchvision cudatoolkit=9.2 -c pytorch然后按如下方式安装 PyTorch,例如,如果您的 cuda 版本是 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.如果您收到 glibc 版本错误,请尝试安装早期版本的 PyTorch。

If neither of the above options work, then try installing PyTorch from sources.如果以上选项都不起作用,请尝试从源代码安装 PyTorch。

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如果您想设置要安装的特定 PyTorch 版本,请在以下命令中将其设置为 <version_nr>: conda install pytorch=<version_nr> torchvision cudatoolkit=9.2 -c pytorch

For CUDA 10.1:对于 CUDA 10.1:

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

For CUDA 9.2:对于 CUDA 9.2:

conda install pytorch torchvision cudatoolkit=9.2 -c pytorch

For no CUDA:对于没有 CUDA:

conda install pytorch torchvision cpuonly -c pytorch

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.不确定您是否已经解决了您的问题,但我之前遇到过完全相同的问题,因为我试图在集群上安装 pytorch 并且我没有 root 访问权限。 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 .您需要将 glibc 下载到您的目录中,并将环境变量 LD_LIBRARY_PATH 设置为您本地的 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要在本地安装 glibc,我会将您指向我阅读的该线程以解决我的问题

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). https://stackoverflow.com/a/38317265/5662642 (安装时不要设置--prefix=/opt/glibc-2.14,您可能希望将其设置为您有权访问的其他目录)。 Hope it works for you希望这对你有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM