一、命令行pip install tensorflow
安装成功,但是import tensorflow as tf 报错 ImportError: DLL load failed: 找不到指定的模块
解决:
(1)打开https://visualstudio.microsoft.com/zh-hans/downloads/?rr=https%3A%2F%2Fsocial.msdn.microsoft.com%2FForums%2Fvstudio%2Fen-US%2Fe653a57a-bc32-4134-87bf-df33058f0531%2Fdownload-microsoft-visual-c-2017-redistributable%3Fforum%3Dvssetup
(2)下载
解决了。
二、继续报错
2020-07-14 10:10:01.462743: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-07-14 10:10:01.467051: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
1、安装cudahttps://developer.nvidia.com/cuda-toolkit-archive
安装路径:D:\Users\LiLy\AppData\Local\CUDA验证是否安装成功nvcc --version
2、下载cudart64_101.dll
https://cn.dll-files.com/cudart64_101.dll.html
并将cudart64_101.dll手动添加到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin里面
3、安装cudnnhttps://developer.nvidia.com/rdp/cudnn-archive
(卸载cuda11.0,重新安装cuda10.0)
---解压cundd文件夹;把解压文件夹里的文件拷贝到安装目录对应的位置
三、
AttributeError: module 'tensorflow' has no attribute 'Session'
解决: 使用tensorflow 2.x版本的接口进行调用
tf.Session() --> tf.compat.v1.Sesion()
四、
>>> import tensorflow as tf
>>> hello=tf.constant('hello.world')
2020-07-15 11:18:14.008439: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x141c6aecff0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-15 11:18:14.014420: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
>>> sess=tf.compat.v1.Session()
>>> print(sess.run(hello))
Traceback (most recent call last):
File "", line 1, in
File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 958, in run
run_metadata_ptr)
File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1106, in _run
raise RuntimeError('The Session graph is empty. Add operations to the '
RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
>>>
解决:
1.tf.compat.v1.disable_eager_execution() #保证sess.run()可以正常运行
import tensorflow as tf
tf.compat.v1.disable_eager_execution() #保证sess.run()能够正常运行
hello = tf.constant('hello,tensorflow')
sess= tf.compat.v1.Session()#版本2.0的函数
print(sess.run(hello))
2.pip install hanlp;pip install tensorflow==2.0.0;pip install tensorflow-gpu==2.0.0
>>> import tensorflow as tf
2020-07-15 15:50:40.173874: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
>>> tf.compat.v1.disable_eager_execution()
>>> hello=tf.constant('helloworld')
>>> sess=tf.compat.v1.Session()
2020-07-15 15:51:44.366010: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-07-15 15:51:44.435907: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce GT 530 major: 2 minor: 1 memoryClockRate(GHz): 1.399
pciBusID: 0000:01:00.0
2020-07-15 15:51:44.442088: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2020-07-15 15:51:44.453150: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1700] Ignoring visible gpu device (device: 0, name: GeForce GT 530, pci bus id: 0000:01:00.0, compute capability: 2.1) with Cuda compute capability 2.1. The minimum required Cuda capability is 3.5.
2020-07-15 15:51:44.464423: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-07-15 15:51:44.467980: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]
>>> print(sess.run(hello))
b'helloworld'
>>>
太心酸了。反正遇到问题就试,总会解决