Crontab和sudo中无法使用TensorFlow ImportError libcublas.so.9.0
最近因?yàn)樘厥獾脑蛑匦掳惭b了python,但是引發(fā)了一個(gè)很嚴(yán)重的問題——TensorFlow不好使了。
比如我下面這個(gè)執(zhí)行文件test.py:
import tensorflow as tf print(tf.__version__)得到的結(jié)果:
ubuntu@ubuntu:~/workspace$ sudo python test.py Traceback (most recent call last):File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>from tensorflow.python.pywrap_tensorflow_internal import *File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>_pywrap_tensorflow_internal = swig_import_helper()File "/home/ubuntu/.local/lib/python3.6/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 "/usr/local/python3/lib/python3.6/imp.py", line 243, in load_modulereturn load_dynamic(name, filename, file)File "/usr/local/python3/lib/python3.6/imp.py", line 343, in load_dynamicreturn _load(spec) ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directoryDuring handling of the above exception, another exception occurred:Traceback (most recent call last):File "test.py", line 1, in <module>import tensorflow as tfFile "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-importFile "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>from tensorflow.python import pywrap_tensorflowFile "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>raise ImportError(msg) ImportError: Traceback (most recent call last):File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>from tensorflow.python.pywrap_tensorflow_internal import *File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>_pywrap_tensorflow_internal = swig_import_helper()File "/home/ubuntu/.local/lib/python3.6/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 "/usr/local/python3/lib/python3.6/imp.py", line 243, in load_modulereturn load_dynamic(name, filename, file)File "/usr/local/python3/lib/python3.6/imp.py", line 343, in load_dynamicreturn _load(spec) ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directoryFailed to load the native TensorFlow runtime.See https://www.tensorflow.org/install/errorsfor some common reasons and solutions. Include the entire stack trace above this error message when asking for help.直接使用Python可以執(zhí)行,但是sudo或者crontab定時(shí)任務(wù)都無法正常運(yùn)行。
使用find命令查找文件
find / -name libcublas.so.9.0可以發(fā)現(xiàn)在我安裝的目錄下:/usr/local/cuda-9.0/lib64
google后,發(fā)現(xiàn)有個(gè)鏈接跟我遇到的情況很像:https://github.com/tensorflow/tensorflow/issues/15604
原來是動(dòng)態(tài)鏈接庫沒有正常鏈接到,改正的方法就是在環(huán)境變量或者配置文件中添加。環(huán)境變量之前已經(jīng)配過了,但是仍然不好使。
就嘗試使用配置文件:
cat /etc/ld.so.confinclude /etc/ld.so.conf.d/*.conf然后創(chuàng)建新的配置文件
vi /etc/ld.so.conf.d/cuda.conf添加如下內(nèi)容: /usr/local/cuda-9.0/lib64再次執(zhí)行l(wèi)dconfig -v | grep libcu
ubuntu@ubuntu:/usr/local/cuda-9.0/lib64$ ldconfig -v | grep libcu /sbin/ldconfig.real: Path `/usr/lib/nvidia-384' given more than once /sbin/ldconfig.real: Path `/usr/lib32/nvidia-384' given more than once /sbin/ldconfig.real: Path `/lib/x86_64-linux-gnu' given more than once /sbin/ldconfig.real: Path `/usr/lib/x86_64-linux-gnu' given more than once /sbin/ldconfig.real: /lib/x86_64-linux-gnu/ld-2.23.so is the dynamic linker, ignoringlibcufft.so.9.0 -> libcufft.so.9.0.176libcuinj64.so.9.0 -> libcuinj64.so.9.0.176libcurand.so.9.0 -> libcurand.so.9.0.176libcufftw.so.9.0 -> libcufftw.so.9.0.176libcudart.so.9.0 -> libcudart.so.9.0.176libcublas.so.9.0 -> libcublas.so.9.0.176libcusparse.so.9.0 -> libcusparse.so.9.0.176libcusolver.so.9.0 -> libcusolver.so.9.0.176libcudnn.so.7 -> libcudnn.so.7.4.1libcups.so.2 -> libcups.so.2再次執(zhí)行sudo python test.py就沒問題了。
轉(zhuǎn)載于:https://www.cnblogs.com/xing901022/p/10211407.html
總結(jié)
以上是生活随笔為你收集整理的Crontab和sudo中无法使用TensorFlow ImportError libcublas.so.9.0的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Leetcode 188.买卖股票的最佳
- 下一篇: [BZOJ2456/ZOJ2132]mo