win10本机cuda与anaconda虚拟环境目标安装cuda版本不匹配:tensorflow-gpu1.12+CUDA9.0+cuDNN7.1.4

本篇文章写在准备用gpu跑深度学习代码的时候,因为cpu着实有点太慢了。
原本的代码是基于tensorflow1.12框架的,为了避免大幅度的代码改动,选择安装tensorflow-gpu1.12
1.首先,用conda命令创建虚拟环境

conda create -n evn-name python=<指定python版本>

2.激活虚拟环境

conda activate evn-name 

3.安装tensorflow-gpu 1.12,这里用conda的时候一直停在solving environment,所以用了pip命令,这里需要提一句的是,anaconda4.8版本中,在conda create新的环境时,已经默认在新环境装了pip,此时进入该环境后,用pip命令安装的包,默认会装在本环境中,不必担心pip一个包后后会将其他环境的包改变版本的情况

pip install tensorflow-gpu==1.12 -i https://pypi.tuna.tsinghua.edu.cn/simple

4.安装CUDA和cuDNN
需要自行查找各个tensorflow版本对应 的CUDA和cuDNN版本,这里tensorflow-gpu 1.12 对应的CUDA版本为9.0,cuDNN版本为7.1.4

通过"conda search tensorflow-gpu", 可以看到有满足安装版本要求的tensorflow-gpu
在这里插入图片描述
通过命令: "conda search cudatoolkit"来看一下是否有此cudatoolkit的安装包
在这里插入图片描述
同理,可以通过conda search cudnn来查看目前镜像源里存在的cudnn版本

按理来说,是可以通过

conda install cudatoolkit==9.0

conda install cudnn==7.1.4

来安装的,但不出意外,出意外了
他一直卡在solving environment
所以,参考了这篇文章
链接: conda虚拟环境中安装cuda和cudnn,再也不用头疼版本号的问题了
为什么参考这篇文章呢,因为我的本机cuda是11.2,而我的代码是基于tensorflow1.12的,而1.12必须对应cuda9.0,如果我的代码支持tensorflow2.0的话,可以直接安装一个tensorflow2.0就可以了,cuda和cudnn会直接打包下载和安装
而且,通常情况下,在Anaconda虚拟环境中只能安装与主机系统上已安装的CUDA版本兼容的CUDA Toolkit版本。因此,如果您的本地系统上已经安装了CUDA 11.2,那么在Anaconda虚拟环境中安装CUDA 9.0可能会遇到兼容性问题。
请注意,CUDA Toolkit包括与主机系统和其他依赖项紧密集成的库和驱动程序。如果您在Anaconda虚拟环境中使用不兼容的CUDA版本,可能会导致不稳定或错误的行为。
但,我没得选
(1)执行上述命令后,会显示出源内所有的cuda版本,以及下载地址,如图所示(这里借图,所以地址是linux,我自己的是win10下的,侵权删)

conda search cudatoolkit --info

在这里插入图片描述
(2)把命令复制到浏览器,会自动下载对应版本的安装包
(3)执行如下命令进行安装,因为是通过本地安装的,所以需要写明本地包的路径

# 然后安装本地包
conda install --use-local 本地cuda包所在的路径

(4)cudnn的安装同理,相关命令如下

conda search cudnn --info #查看下载地址
conda install --use-local 本地cudnn包所在的路径 #安装

下载的安装包如图
在这里插入图片描述
安装成功的终端是这样的
在这里插入图片描述

如果要测试的话,可以运行测试程序:

# -*- coding: utf-8 -*-
import tensorflow as tf

# 验证CUDA是否安装成功
print("CUDA available:", tf.test.gpu_device_name() is not None)

# 打印当前GPU设备列表
print("GPU devices:")
print(tf.test.gpu_device_name())

# 验证cuDNN是否安装成功
print("cuDNN available:", tf.test.is_built_with_cuda())

测试结果如下
在这里插入图片描述

这里更新一下2023.11.24

到后来程序运行的时候发现,tensorflow-gpu1.12版本对应的cudnn版本需要>=7.2.1,所以需要重新+安装一个更高版本的cudnn,但一定要是7.x的
具体提示信息如下:

E tensorflow/stream_executor/cuda/cuda_dnn.cc:363] Loaded runtime CuDNN library: 7.1.4 but source was compiled with: 7.2.1.  CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.
2023-11-24 12:00:03.598839: E tensorflow/stream_executor/cuda/cuda_dnn.cc:363] Loaded runtime CuDNN library: 7.1.4 but source was compiled with: 7.2.1.  CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.

这里提示一下啊,我用conda search cudnn --info查找cudnn7.2.1的下载地址时,并没有找到,想来并不常用,所以我直接下载了cudnn7.3.1的安装包,事实证明是没有问题的

  • 37
    点赞
  • 53
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.支持mkl,无MPI; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 配置信息: hp@dla:~/work/ts_compile/tensorflow$ ./configure WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown". You have bazel 0.19.1 installed. Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3 Found possible Python library paths: /usr/local/lib/python3.5/dist-packages /usr/lib/python3/dist-packages Please input the desired Python library path to use. Default is [/usr/local/lib/python3.5/dist-packages] Do you wish to build TensorFlow with XLA JIT support? [Y/n]: XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with ROCm support? [y/N]: No ROCm support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10.0]: Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0 Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.3.1 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: Do you wish to build TensorFlow with TensorRT support? [y/N]: y TensorRT support will be enabled for TensorFlow. Please specify the location where TensorRT is installed. [Default is /usr/lib/x86_64-linux-gnu]:/home/hp/bin/TensorRT-5.0.2.6-cuda10.0-cudnn7.3/targets/x86_64-linux-gnu Please specify the locally installed NCCL version you want to use. [Default is to use https://github.com/nvidia/nccl]: Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 6.1,6.1,6.1]: Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by adding "--config=" to your build command. See .bazelrc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. --config=gdr # Build with GDR support. --config=verbs # Build with libverbs support. --config=ngraph # Build with Intel nGraph support. --config=dynamic_kernels # (Experimental) Build kernels into separate shared objects. Preconfigured Bazel build configs to DISABLE default on features: --config=noaws # Disable AWS S3 filesystem support. --config=nogcp # Disable GCP support. --config=nohdfs # Disable HDFS support. --config=noignite # Disable Apacha Ignite support. --config=nokafka # Disable Apache Kafka support. --config=nonccl # Disable NVIDIA NCCL support. Configuration finished 编译: hp@dla:~/work/ts_compile/tensorflow$ bazel build --config=opt --config=mkl --verbose_failures //tensorflow/tools/pip_package:build_pip_package 卸载已有tensorflow: hp@dla:~/temp$ sudo pip3 uninstall tensorflow 安装自己编译的成果: hp@dla:~/temp$ sudo pip3 install tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值