python tensorflow 安装步骤和踩过的坑

1. 下载python 并安装,,可能需要配置环境变量

成功后在cmd上可以看到下面的python情况,这个可以百度安装python。

PS D:\LearningFiles\python> python
Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

2. 更新pip

pip install --upgrade pip

报错
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: ‘d:\programes\python38\scripts\pip.exe’
Consider using the --user option or check the permissions.

解决办法:
python.exe -m pip install --upgrade pip

报错D:\Programes\python38\python.exe: No module named pip
解决办法: python -m ensurepip,后面就可以执行了

3. 安装tensorflow

pip install --upgrade tensorflow

(当时默认安装的是2.3.1的tensorflow版本,可以使用pip list 查看)
tensorboard 2.3.0
tensorboard-plugin-wit 1.7.0
tensorflow 2.3.1
tensorflow-estimator 2.3.0

4.运行例子,处理错误

python -c "import tensorflow as tf;print(tf.test.is_gpu_available())"
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

这里汇报很多dll 文件缺失的错误。需要下载显卡的相关库文件,我这里用的是英伟达的显卡,就去官方网站下载了。
主要包括CUDA(这个是一个开发环境,包括缺失的dll),和cudnn(也是一个需要的dll)主要是需要下载下面两个库:

  • CUDA:https://developer.nvidia.com/cuda-toolkit

这个网站需要注册才能下载,那就注册咯,一般首页提供的是最新版本的下载。
进入下载页,后需要选择平台的页面,网页偏下的位置,有一个Archive of Previous CUDA Releases,这里可以下载其他版本的CUDA,将里面bin里面的dll文件复制到C:\Windows\System32 里面

  • cudnn:https://developer.nvidia.com/cudnn

这个下载是一个压缩文件,cudnn-10.1-windows10-x64-v7.6.5.32.zip,解压后将里面bin里面的dll文件复制到C:\Windows\System32 里面

5. 再运行例子

python -c "import tensorflow as tf;print(tf.test.is_gpu_available())"

如果出现其他dll都可以成功,只有cublas64_10.dll 无法加载的问题

  1. python从官方网站重新下载安装,如果是win10应用商店下载的python会出现这个问题。
  2. tensorflow 从2.3 降回2.2 据说也可以解决这个问题。

成功后例子运行玩会返回True(最后一行是True),

PS D:\LearningFiles\python> python -c “import tensorflow as
tf;print(tf.test.is_gpu_available())”

2020-10-21 22:50:29.976743: I
tensorflow/stream_executor/platform/default/dso_loader.cc:48]
Successfully opened dynamic library cudart64_101.dll 2020-10-21
22:50:30.014353: I
tensorflow/stream_executor/platform/default/dso_loader.cc:48]
Successfully opened dynamic library cublas64_10.dll 2020-10-21
22:50:30.055069: I
tensorflow/stream_executor/platform/default/dso_loader.cc:48]
Successfully opened dynamic library cufft64_10.dll 2020-10-21
22:50:30.072551: I
tensorflow/stream_executor/platform/default/dso_loader.cc:48]
Successfully opened dynamic library curand64_10.dll 2020-10-21
22:50:30.162110: I
tensorflow/stream_executor/platform/default/dso_loader.cc:48]
Successfully opened dynamic library cusolver64_10.dll 2020-10-21
22:50:30.192244: I
tensorflow/stream_executor/platform/default/dso_loader.cc:48]
Successfully opened dynamic library cusparse64_10.dll 2020-10-21
22:50:30.269023: I
tensorflow/stream_executor/platform/default/dso_loader.cc:48]
Successfully opened dynamic library cudnn64_7.dll
True

7. 网盘资源打包

所有安装文件看这里,文件很大,慎用,网盘的速度你们懂的。官方网站的速度也不慢。

链接:https://pan.baidu.com/s/1HhRCjza013V1-B7Wyq_6yQ
提取码:veou

2020.11.03 更新:
已经放弃用pip安装tensorflow了,改用anaconda环境了。
https://zhuanlan.zhihu.com/p/46579831

**最后的最后,写文章不易,如果有帮助到你,请随手给个赞 **

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值