windows下安装tensorflow(GPU/CPU)

ERROR: You appear to be running an X server; please exit X before            
         installing.  For further details, please see the section INSTALLING   
         THE NVIDIA DRIVER in the README available on the Linux driver         
         download page at www.nvidia.com.

sudo ./NVIDIA-Linux-x86_64-535.86.05.run -no-opengl-files -no-x-check

ERROR: An NVIDIA kernel module 'nvidia' appears to already be loaded in your
         kernel.  This may be because it is in use (for example, by an X       
         server, a CUDA program, or the NVIDIA Persistence Daemon), but this   
         may also happen if your kernel was configured without support for     
         module unloading.  Please be sure to exit any programs that may be    
         using the GPU(s) before attempting to upgrade your driver.  If no     
         GPU-based programs are running, you know that your kernel supports    
         module unloading, and you still receive this message, then an error   
         may have occurred that has corrupted an NVIDIA kernel module's usage  
         count, for which the simplest remedy is to reboot your computer.

sudo apt-get remove --purge nvidia*

一、安装tensorflow_gpu

官方安装网址 TensorFlow (google.cn)

(1)安装anaconda3

(2)打开 Anaconda Prompt

(3)创建环境

        【注意】这里只是配置好环境,并未安装tensorflow

          conda create -n tensorflow_gpu python=3.9

        (python版本参考使用 pip 安装 TensorFlow (google.cn)

       

       在 Windows 环境中从源代码构建  |  TensorFlow (google.cn)         

cudnn下载:cuDNN Archive | NVIDIA Developer

cuda下载:CUDA Toolkit Archive | NVIDIA Developer

安装cuda,解压cudnn-11.2-windows-x64-v8.1.0.77,文件夹重命名为cudnn,放入cuda的安装文件夹里。

编辑环境变量cuda和cudnn:

      

        出现:

        

 在anaconda安装目录下envs文件夹下可以看到:

         

(4)激活

        conda activate tensorflow_gpu

  (5) 安装 tensorflow-gpu

        在线安装:

                                pip install tensorflow-gpu==2.6.0

                                或

                                pip install --ignore-installed --upgrade tensorflow_gpu==2.6.0

       离线安装:

               下载tensorflow-gpu安装包: tensorflow-gpu · PyPI

               pip install C\tensorflow_gpu-2.6.0-cp39-cp39-win_amd64.whl

                离线安装时,会联网下载第三方库,出现超时错误时,忽略。不停重复安装即可

 完成后:

  

运行tensorflow程序,在cmd里运行nvidia-smi 查看gpu使用情况。

二、安装tensorflow

conda create - -name tensorflow python=3.10

                     

    

三、问题

(1)ImportError: cannot import name 'dtensor' from 'tensorflow.compat.v2.experimental'

原因:keras与tensorflow版本不匹配,将keras 2.9.0 降至2.6.0

 在tensorflow-gpu环境下执行:pip install keras==2.6.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值