windows10+gpu版本的tensorflow全过程

搞了三天,踩坑无数,终于搞定了。
经验1:一定要版本对应 tensorflow-gpu、CUDA、cuDNN
经验2:装在windows上的话,较高版本/较新版本的上面三个不支持!

1.新建环境 conda create -n gpu_env python=3.7 (一开始搞了3.8以上!!!千万不要,因为python3.8对应的tensorflow-gpu并不能用在windows上,在一个网页看到的这句话,后面有截图)

2.激活环境conda activate gpu_env(gpu_env是环境名)

3.安装tensorflow-gpu pip install -i https://pypi.mirrors.ustc.edu.cn/simple tensorflow-gpu==2.6.0 (后面的镜像源可以换,阿里云、豆瓣的似乎更好用一些,看到一些帖子说清华的会不稳定。在这里踩到的坑很多,比如显示安装失败、一直salving environment;需要注意的是,要先装tensorflow-gpu!另外,最重要的是,不能超过2.11!!)

4.下载jupyter notebook pip install Jupyter -i https://pypi.doubanio.com/simple (尝试了不用镜像–显示失败or一直安装中;尝试在anaconda里install,一直不成功;尝试在VScode里装,一直不成功;最后用这个带镜像的,成功~)

5.安装CUDA工具包 我的是11.2版本(先用nvidia-smi查看自己设备能使用的CUDA的最高版本,这里显示的是12.2,只要低于它即可)
在这里插入图片描述
6.安装cuDAA库 我的是8.1版本(要版本对应) (在这里看到了那句windows不支持2.11以上的tensorflow-gpu!!!!)
在这里插入图片描述
7.验证GPU是否可用 (返回true表明gpu版本的tensorflow可用;如果显示false,说明tensorflow-gpu或CUDA或cuDNN有版本错误;后面的GPUS为1说明只有一个GPU设备)
在这里插入图片描述
完成!

中间遇到的问题及解决方案:

问题1:新建环境时报错:CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64/current_repodata.json
法1:在anaconda prompt执行以下命令
conda config --add channels - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
然后在“C:\Users\Administrator(你的用户名)”目录下找到“.condarc”文件并打开,若channels下面有-default,删除-default,保存退出,重新新建环境
法二:将“.condarc”文件中的https改成http将“.condarc”文件中的https改成http
法三:离线创建:conda config --set offline true,重新新建环境
(盲猜,以后遇到报错httperror/与网络相关的问题时,都用第三种方式解决)

问题2:安装gpu-tensorflow时,报错:
tensorboard 2.11.2 has requirement protobuf<4,>=3.9.2, but you’ll have protobuf 4.24.4 which is incompatible.
法一:pip install --upgrade tensorboard (这个方法不可取,因为改变它的板本就和tensorflow的不对应了)
法二:pip install protobuf==3.9.2

问题3:you are using pip version 10.0.1,however version 23.3.1 is available
法一:不要直接win+R然后cmd,而是要选择“开始”—“Windows系统”—“命令提示符”—右键“以管理员身份运行”;不要用家用WiFi,开手机热点连接;管理员身份运行命令提示符后,使用镜像下载升级,代码如下:python -m pip install --upgrade pip -i https://pypi.douban.com/simple

问题4:安装gpu-tensorflow时,报错:ERROR: Cannot uninstall ‘wrapt’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
法一:更新一系列包:pip install -U --ignore-installed wrapt enum34 simplejson netaddr,在重新安装(没用,报错)
法二:手动卸载电脑中所有有关wrapt的文件,然后重新安装

问题5:
DEPRECATION: pandas 0.23.4 has a non-standard dependency specifier pytz>=2011k. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of pandas or contact the author to suggest that they release a version with a conforming dependency specifiers. Discussion can be found at https://github.com/pypa/pip/issues/12063
法一:pip install --upgrade pandas -i https://pypi.doubanio.com/simple/

问题6:安装gpu-tensorflow时,报错:ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorflow-intel 2.11.0 requires libclang>=13.0.0, which is not installed.
tensorflow-intel 2.11.0 requires packaging, which is not installed.
tensorflow-intel 2.11.0 requires tensorflow-io-gcs-filesystem>=0.23.1; platform_machine != “arm64” or platform_system != “Darwin”, which is not installed.
tensorflow-intel 2.11.0 requires absl-py>=1.0.0, but you have absl-py 0.15.0 which is incompatible.
tensorflow-intel 2.11.0 requires flatbuffers>=2.0, but you have flatbuffers 1.12 which is incompatible.
tensorflow-intel 2.11.0 requires numpy>=1.20, but you have numpy 1.19.5 which is incompatible.
解决:尝试先卸载它,以避免版本冲突。python -m pip uninstall tensorflow-intel
然后重新下载tensorflow-gpu

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值