Anaconda 读取错误的 CUDA 版本

fil*_*lip 5 conda torch tensorflow pytorch

我有一个带有 PyTorch 和 Tensorflow 的 conda 环境,它们都需要 CUDA 9.0(来自 conda 的~cudatoolkit 9.0)。在使用torchvision和cudatoolkit(就像他们在他们的网站上提供的)安装pytorch之后,我想安装Tensorflow,这里的问题是我收到这个错误:

Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: / 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed                                                                                                   

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - tensorflow==1.12.0 -> python[version='2.7.*|3.6.*']
  - tensorflow==1.12.0 -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0']

Your python: python=3.5

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

The following specifications were found to be incompatible with your system:

  - feature:/linux-64::__cuda==10.2=0
  - feature:|@/linux-64::__cuda==10.2=0

Your installed version is: 10.2
Run Code Online (Sandbox Code Playgroud)

如果我在我的主机或激活的 conda 环境上运行nvccnvidia-smi,我会知道我已经安装了 CUDA 10.2,即使conda list显示我安装了 cudatoolkit 9.0。有什么解决办法吗?

编辑:

运行此代码示例时:

# setting device on GPU if available, else CPU
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print('Using device:', device)
print()

#Additional Info when using cuda
if device.type == 'cuda':
    print(torch.cuda.get_device_name(0))
    print('Memory Usage:')
    print('Allocated:', round(torch.cuda.memory_allocated(0)/1024**3,1), 'GB')
    print('Cached:   ', round(torch.cuda.memory_cached(0)/1024**3,1), 'GB')


print(torch.version.cuda)
Run Code Online (Sandbox Code Playgroud)

我得到这个输出:

GeForce GTX 1050
Memory Usage:
Allocated: 0.0 GB
Cached:    0.0 GB
9.0.176
Run Code Online (Sandbox Code Playgroud)

所以 PyTorch 确实获得了正确的 CUDA 版本,我只是无法安装 tensorflow-gpu。

trs*_*chn 7

如果我在主机或激活的环境上运行nvcc或,我会发现我已经安装了,即使显示已安装。有什么办法解决这个问题吗?nvidia-smicondaCUDA 10.2conda listcudatoolkit 9.0

cudatoolkit不附带编译器 ( nvcc),因此当您运行时,nvcc您会从系统范围的安装启动编译器。这就是为什么它打印10.2而不是9.0,并pytorch看到本地cudatoolkit.

anaconda/包/cudatoolkit

该 CUDA 工具包包括 GPU 加速库以及适用于 Conda 生态系统的 CUDA 运行时。如需包含编译器和开发工具的完整 CUDA 工具包,请访问https://developer.nvidia.com/cuda-downloads

从您上面的评论中我了解到您正在使用python=3.5.6. 因此,首先您应该tensorflow py35使用以下命令搜索可用的版本:

conda search tensorflow | grep py35
Run Code Online (Sandbox Code Playgroud)

我有以下输出:

tensorflow                     1.9.0 eigen_py35h8c89287_1  pkgs/main           
tensorflow                     1.9.0 gpu_py35h42d5ad8_1  pkgs/main           
tensorflow                     1.9.0 gpu_py35h60c0932_1  pkgs/main           
tensorflow                     1.9.0 gpu_py35hb39db67_1  pkgs/main           
tensorflow                     1.9.0 mkl_py35h5be851a_1  pkgs/main           
tensorflow                    1.10.0 eigen_py35h5ed898b_0  pkgs/main           
tensorflow                    1.10.0 gpu_py35h566a776_0  pkgs/main           
tensorflow                    1.10.0 gpu_py35ha6119f3_0  pkgs/main           
tensorflow                    1.10.0 gpu_py35hd9c640d_0  pkgs/main           
tensorflow                    1.10.0 mkl_py35heddcb22_0  pkgs/main
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,没有 的tensorflow 1.12.0构建py35,这就是您收到该错误的原因。您可以尝试检查其他conda渠道,例如conda-forge

conda search tensorflow -c conda-forge | grep py35
Run Code Online (Sandbox Code Playgroud)

但这没有帮助:

tensorflow                     0.9.0          py35_0  conda-forge         
tensorflow                    0.10.0          py35_0  conda-forge         
tensorflow                 0.11.0rc0          py35_0  conda-forge         
tensorflow                 0.11.0rc2          py35_0  conda-forge         
tensorflow                    0.11.0          py35_0  conda-forge         
tensorflow                    0.12.1          py35_0  conda-forge         
tensorflow                    0.12.1          py35_1  conda-forge         
tensorflow                    0.12.1          py35_2  conda-forge         
tensorflow                     1.0.0          py35_0  conda-forge         
tensorflow                     1.1.0          py35_0  conda-forge         
tensorflow                     1.2.0          py35_0  conda-forge         
tensorflow                     1.2.1          py35_0  conda-forge         
tensorflow                     1.3.0          py35_0  conda-forge         
tensorflow                     1.4.0          py35_0  conda-forge         
tensorflow                     1.5.0          py35_0  conda-forge         
tensorflow                     1.5.1          py35_0  conda-forge         
tensorflow                     1.6.0          py35_0  conda-forge         
tensorflow                     1.8.0          py35_0  conda-forge         
tensorflow                     1.8.0          py35_1  conda-forge         
tensorflow                     1.9.0 eigen_py35h8c89287_1  pkgs/main           
tensorflow                     1.9.0 gpu_py35h42d5ad8_1  pkgs/main           
tensorflow                     1.9.0 gpu_py35h60c0932_1  pkgs/main           
tensorflow                     1.9.0 gpu_py35hb39db67_1  pkgs/main           
tensorflow                     1.9.0 mkl_py35h5be851a_1  pkgs/main           
tensorflow                     1.9.0          py35_0  conda-forge         
tensorflow                    1.10.0 eigen_py35h5ed898b_0  pkgs/main           
tensorflow                    1.10.0 gpu_py35h566a776_0  pkgs/main           
tensorflow                    1.10.0 gpu_py35ha6119f3_0  pkgs/main           
tensorflow                    1.10.0 gpu_py35hd9c640d_0  pkgs/main           
tensorflow                    1.10.0 mkl_py35heddcb22_0  pkgs/main           
tensorflow                    1.10.0          py35_0  conda-forge
Run Code Online (Sandbox Code Playgroud)

因此,可能的解决方案是:

  1. 安装较旧的可用版本之一tensorflow 1.10.0 gpu_py35
  2. 切换到python 3.6
conda search tensorflow | grep py36

...
tensorflow                    1.11.0 gpu_py36h4459f94_0  pkgs/main           
tensorflow                    1.11.0 gpu_py36h9c9050a_0  pkgs/main           
...        
tensorflow                    1.12.0 gpu_py36he68c306_0  pkgs/main           
tensorflow                    1.12.0 gpu_py36he74679b_0  pkgs/main
...         
Run Code Online (Sandbox Code Playgroud)

请注意,版本 >=1.13.1 不支持CUDA 9.

  1. 使用pip install内部condaenv 来安装缺少的tensorflow构建,因为pip托管更多构建组合:经过测试的构建配置

以下是 Anaconda 的一些最佳实践,如何使用pipw/ conda在 Conda 环境中使用 Pip

  1. 最后一个选项是构建您自己的缺失condaconda-build