python中使用tensorflow的問題描述
在python3中,導入tensorflow時遇到了以下問題:
>>> import tensorflow as tf
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/usr/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/usr/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
考慮到版本375有這個BUG:從睡眠模式喚醒電腦後,沿著窗口邊界有奇怪的東西,我使用的Nvidia驅動程序是381.09測試版。
而且,我已經安裝了CUDA 8.0和cuDNN-v6.0:
rharish@rharish-GL552VW:~$ cd /usr/local
rharish@rharish-GL552VW:/usr/local$ ls
bin cuda etc include man share
computecpp cuda-8.0 games lib sbin src
此外,libcusolver.so.8.0也存在於/usr/local/cuda/lib64/
中:
libcusolver.so.8.0 in ‘ls’ output
我已經卸載並重新安裝了CUDA,cuDNN,還從源代編譯安裝過tensorflow。但是,隻要將Nvidia驅動程序更新為381.09版本,這個問題就會發生。需要怎麽解決這個問題?
最佳解決辦法
經驗證有效的解決方案:
重新安裝nvidia-381,CUDA-8.0(使用runfile)和cuDNN 6.0,然後在.bashrc
文件中添加了以下內容:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/
另外一種解決思路
不需要重新安裝上述的各種軟件包,隻需要安裝nvidia-cuda-dev
:
sudo apt install nvidia-cuda-dev
然後安裝cuDNN
(可以從這裏下載:https://developer.nvidia.com/cudnn),最後相應地設置LD_LIBRARY_PATH
指向cuda/lib64
即可。
延伸閱讀:《真正從零開始,TensorFlow詳細安裝入門圖文教程!》,地址:https://www.leiphone.com/news/201606/ORlQ7uK3TIW8xVGF.html