win10 tensorflow2.2 安裝踩坑總結

在這裏插入圖片描述
學習新技術有兩座大山,一座是配置環境,另一座是調試bug

最近想了解一下新版的tensorflow,於是乎就打算配置一下環境跑幾個模型玩玩,誰知道竟然是這麼坎坷。

安裝tensorflow2.2 版本 cpu和gpu版的時候

直接pip install tensorflow

肯定是不行的,慢到令人發狂
在這裏插入圖片描述

平常安裝工具都使用清華源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu

但是不知道爲什麼,使用清華源地址,網絡老是莫名其妙的中斷,但是本地測了一下網絡也沒啥問題。

於是乎換了一個包不是很全的豆瓣地址
http://pypi.douban.com/simple/

竟然cpu和gpu版穩穩當當的一遍安裝成功

然後噩夢從此開始

打印一下版本號,看一下環境

import tensorflow as tf

print(tf.__version__)
Failed to load the native TensorFlow runtime.

Traceback (most recent call last):

  File "<ipython-input-6-64156d691fe5>", line 1, in <module>
    import tensorflow as tf

  File "C:\Users\HonorVan\AppData\Roaming\Python\Python36\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import

  File "C:\Users\HonorVan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow

  File "C:\Users\HonorVan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)

ImportError: Traceback (most recent call last):
  File "C:\Users\HonorVan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\HonorVan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\HonorVan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "D:\ProgramData\Anaconda3\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "D:\ProgramData\Anaconda3\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模塊。


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

於是查看官網安裝錯誤說明和google一下。
有人說python版本和tensorflow版本不匹配,要麼降低python版本,要麼降低tensorflow版本。
但是去看了一下官網,沒有問題,我的當前環境爲python3.6.5,安裝tensorflow的版本爲2.2,win10 64位,pip 20.0,OK呀~ 但是爲什麼呢?
在這裏插入圖片描述

有了官網的定心丸,於是開始搜索其他原因,想着先把gpu版卸了,先配置cpu版的。

卸完gpu版還存這個問題。

於是又打開google。

說是缺少一個類庫MSVCP140.DLL。

於是https://www.microsoft.com/en-us/download/details.aspx?id=53587下載安裝。

cpu版算是搞定了。

接下來就是萬惡的gpu加速版了。

依然使用豆瓣源安裝沒啥大問題。

然後安裝cuda和cudnn也沒啥大問題,記得環境變量path配一下。把cudnn的文件複製到cuda的目錄裏就OK了。

但是tf對cuda和cudnn的版本也有要求。

通過報錯,瞭解只能對應裝10.1版本的cuda,10.0的還不行。
在這裏插入圖片描述

然後再找10.1cuda對應的cudnn7.6.5。這個顯卡加速庫算是安裝成功了。

然後又來個驅動和運行版本不對應。

CUDA driver version is insufficient for CUDA runtime versionailed.

看了些文章,說是要卸載工具包,在對應版本安裝。

pip uninstall cudnn ; pip uninstall cudatoolkit
在這裏插入圖片描述

但是看了一眼pip list 根本沒有這個東西。

也有人說更新一下顯卡驅動。

我的筆記本買的比較早了顯卡比較垃圾。

於是找到官網https://www.nvidia.cn/Download/index.aspx?lang=cn
更新了一下。
在這裏插入圖片描述

見證奇蹟的時刻。

終於成功了。

I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1060 computeCapability: 6.1
coreClock: 1.6705GHz coreCount: 10 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 178.99GiB/s
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x22345614f70 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
 I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1060 computeCapability: 6.1
coreClock: 1.6705GHz coreCount: 10 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 178.99GiB/s
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4700 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0, compute capability: 6.1)
I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x223673b0e90 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1060, Compute Capability 6.1

安裝個環境折騰了一下午。

終於翻過了一座大山。

cpu版比較簡單,gpu版坑比較多。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章