w11 conda 虚拟环境cuda+cudnn+tensorflow-gpu(在conda里下cuda和cudnn)

首先选择tensorflow对应的cuda和cudnn

但是CUDA11.2.X不支持win11,CUDA11.8.X版本却可以兼容w11。

那我们标准为Tensorflow2.10.0+cuda11.8+cudnn8.8

欧克,选择好了,开干。

创建python3.10

conda create -n tf210 python==3.10.0

激活虚拟环境

conda activate tf210

添加中科大镜像源

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/


这些命令将显示当前使用的镜像源,并将通道优先级设置为严格,确保首先从中科大的镜像源获取软件包。

conda config --set show_channel_urls yes
conda config --set channel_priority strict

添加完后下载cuda11.8+cudnn8.8,下载不成功多换几个镜像源

conda install cudatoolkit=11.8 cudnn=8.8


两个都下好之后需要添加环境变量,在系统变量里的path添加

C:\ProgramData\Anaconda3\envs\name\Library\bin

name是你的虚拟环境名字

下载tensorflow2.10.0

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

下完了测试一下

python
import tensorflow as tf
print(tf.__version__)
gpus =tf.config.list_physical_devices('GPU')
print(gpus)

战斗,爽!

踩坑事项:

1.注意,虚拟环境用python是可以识别到gpu,但是到了jupyter里就识别不到了,后来才知道需要添加环境变量就ok了
 

CUDA_SDK_PATH = C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.2
CUDA_LIB_PATH = %CUDA_PATH%\lib\x64
CUDA_BIN_PATH = %CUDA_PATH%\bin
CUDA_SDK_BIN_PATH = %CUDA_SDK_PATH%\bin\win64
CUDA_SDK_LIB_PATH = %CUDA_SDK_PATH%\common\lib\x64

2.我本地C盘是有cuda12.3的所以不用担心会不会冲突。

3.最开始我更新cuda12.3的时候踩了很多坑,比如cuda四大杀手。

我的经验是把全部的删掉

再重新下载,因为这样才很简单而且还不容易报错

4.Windows Installer 错误。

无法访问.Windows Installer服务

解决 可恶的联想管家启动项没开

哈哈哈哈哈

参考:

还在系统中安装CUDA?Anaconda虚拟环境中安装CUDA配合Tensorflow-gpu-多版本 - 简书 (jianshu.com)

Tensorflow2.X+cuda+cudnn配置指南(RTX4060+win11+Anaconda3) - MistLuoy - 博客园 (cnblogs.com)

自编译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
自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.无mkl支持; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 TI 配置信息: 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 编译: bazel build --config=opt --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
### 配置 CUDA 11.8 PyTorch 2.1.0 的安装 为了在 Windows 系统上正确配置 CUDA 11.8 PyTorch 2.1.0,以下是详细的说明操作方法。 #### 创建独立环境 建议创建一个新的 Conda 虚拟环境来隔离 Python 版本其他依赖项。通过以下命令创建并激活虚拟环境: ```bash conda create -n pytorch_env python=3.11 conda activate pytorch_env ``` 此步骤有助于避免与其他项目中的库发生冲突[^1]。 #### 安装 CUDA 工具包 对于 CUDA 11.8 的安装,可以通过 `conda` 命令完成。执行如下命令以安装兼容的 `cudatoolkit` 及其附带的 cuDNN 库: ```bash conda install cudatoolkit=11.8 ``` 需要注意的是,虽然某些文档可能提到更高版本CUDA(如 12.x),但在实际测试中发现,PyTorch 2.1.0 对 CUDA 11.8 提供了更好的支持[^2]。 #### 安装 PyTorch 针对特定版本的 PyTorch (即 2.1.0),推荐使用官方提供的脚本来获取适合当前系统的安装指令。运行以下命令可自动检测硬件条件并提供定制化安装方案: ```bash pip install torch==2.1.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 ``` 上述 URL 参数指定了基于 CUDA 11.8 构建的二进制文件位置[^4]。如果 GPU 不可用或者希望仅安装 CPU 支持版本,则需移除该参数或将链接替换为对应的 CPU-only 地址。 #### 测试安装成功与否 验证安装是否成功的常用方式之一是尝试导入模块并在终端打印设备信息: ```python import torch print(torch.__version__) # 输出应显示 '2.1.0' print(torch.cuda.is_available()) # 若有 NVIDIA 显卡则返回 True print(torch.version.cuda) # 返回所使用的 CUDA 版本号, 如'11.8' ``` 以上代码片段能够帮助确认 PyTorch 是否正常加载以及它正在利用哪个版本CUDA 运行时[^3]。 --- #### 注意事项 尽管最新发布的 CUDA 版本通常具备向后兼容能力,但并非所有组合都经过充分测试。因此,在遇到性能瓶颈或功能缺失的情况下,请参照官方文档调整至更稳定的搭配。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值