最近因为特殊的原因重新安装了python,但是引发了一个很严重的问题——TensorFlow不好使了。

比如我下面这个执行文件test.py

import tensorflow as tf
print(tf.__version__)

得到的结果:

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_module
return load_dynamic(name, filename, file)
File "/usr/local/python3/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.9.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 "test.py", line 1, in <module>
import tensorflow as tf
File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/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_module
return load_dynamic(name, filename, file)
File "/usr/local/python3/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory 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.

直接使用Python可以执行,但是sudo或者crontab定时任务都无法正常运行。

使用find命令查找文件

find / -name libcublas.so.9.0

可以发现在我安装的目录下:/usr/local/cuda-9.0/lib64

google后,发现有个链接跟我遇到的情况很像:https://github.com/tensorflow/tensorflow/issues/15604

原来是动态链接库没有正常链接到,改正的方法就是在环境变量或者配置文件中添加。环境变量之前已经配过了,但是仍然不好使。

就尝试使用配置文件:

cat /etc/ld.so.conf

include /etc/ld.so.conf.d/*.conf

然后创建新的配置文件

vi /etc/ld.so.conf.d/cuda.conf

添加如下内容:
/usr/local/cuda-9.0/lib64

再次执行ldconfig -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, ignoring libcufft.so.9.0 -> libcufft.so.9.0.176
libcuinj64.so.9.0 -> libcuinj64.so.9.0.176
libcurand.so.9.0 -> libcurand.so.9.0.176
libcufftw.so.9.0 -> libcufftw.so.9.0.176
libcudart.so.9.0 -> libcudart.so.9.0.176
libcublas.so.9.0 -> libcublas.so.9.0.176
libcusparse.so.9.0 -> libcusparse.so.9.0.176
libcusolver.so.9.0 -> libcusolver.so.9.0.176
libcudnn.so.7 -> libcudnn.so.7.4.1
libcups.so.2 -> libcups.so.2

再次执行sudo python test.py就没问题了。

Crontab和sudo中无法使用TensorFlow ImportError libcublas.so.9.0的更多相关文章

  1. ImportError libcublas.so.9.0

    What to do when you've installed cuda and tensorflow, but you get this error right after you import ...

  2. 安装tensorflow报ImportError: libcublas.so.9.0: cannot open shared object file的解决方法【转】

    本文转载自:https://blog.csdn.net/qq_37274615/article/details/81099738 转载自:https://blog.csdn.net/qysh123/a ...

  3. 导入tensorflow:ImportError: libcublas.so.9.0: cannot open shared object file: No such file or director【转】

    本文转载自:https://blog.csdn.net/ksws0292756/article/details/80034086 版权声明:本文为博主原创文章,转载请一定附上博主原文链接,并署名转自Z ...

  4. pycharm中报ImportError: libcublas.so.9.0错误的解决方法。

    前些天不知为啥cuda不能用了,nvidia-smi也没反应.然后我就重新装了一下cuda.后来使用pycharm远程连接时,居然报错了. ImportError: libcublas.so.9.0: ...

  5. tf-gpu报错:ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory

    错误1:ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory 一般这种问题 ...

  6. ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory 【学习笔记】【原创】

    作者:庄泽彬(欢迎转载,请注明作者) 说明:千辛万苦终于在ubuntu18.04上安装好cuda9.1与cudnn7.0.5,但是导入import tensorflow as tf却报了这个错误. 上 ...

  7. ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

    这是因为我装了tensorflow-gpu 1.5版本,而我用的是cuda 8.0和cudnn6.0,1.5版本要求cuda 9.0,我的做法就是回滚tensorflow版本.

  8. tensorflow-gpu 1.13 提示找不到 libcublas.so.10.0 的问题

    tensorflow-gpu 使用 1.13.1,cuda-10-0已安装好,但启动时依然报错 ImportError: libcublas.so.10.0: cannot open shared o ...

  9. (原)ubuntu中安装tensorflow

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6592052.html 参考网址: https://www.tensorflow.org/install ...

随机推荐

  1. Spring常用注解总结(2)

    @Autowired "自动填装",作用是为了消除代码JAVA代码里面的getter/setter与bean属性中的property. @Autowired默认按类型匹配的方式,在 ...

  2. layui---十分适用于PC端后台的框架

    1.关闭当前页面: top.$(".layui-tab-title").find("li.layui-this>i").click(); 2.调用指定ID ...

  3. WCF 服务的集合管理器的设计

    今天是2019年2月1日,时间过得针对,马上就年底了,当前新年也离我们越来越近了.在此,我也祝福经常浏览我博客的朋友们“新年快乐.阖家欢乐”,来年有一个好彩头.在即将结束这一年之计,写今年的最后一片文 ...

  4. AnjularJS 学习

    一个不错的学习AnjularJS的网站,可以在线实践:http://www.runoob.com/angularjs/angularjs-tutorial.html

  5. 一个c程序反汇编过程(zz)

    zz from http://blog.luoyuanhang.com/ 最基本的反汇编方法是gdb xxx: disassemble main/其他函数 #反汇编一个简单的C程序并分析 C 源码: ...

  6. HTML元素的分类

    HTML元素的分类 EC前端 - HTML教程 块元素 div:无语义,常用于布局 aside:表示article元素的内容之外的与article元素的内容相关内容 figure:表示一段独立的流内容 ...

  7. dede织梦后台-退出空白,注销空白,打开空白,登录返回首页,登录返回登录页面

    24.php 5.4版本 后台500错误,打开空白的问题 不兼容 登录时空白 后台空白 24-1./include/userlogin.class.php 今天把电脑上的phpStudy升级到2013 ...

  8. 加密 解密 RSA & AES & DES

    git: https://github.com/XHTeng/XHCryptorTools rsa RSA加解密中必须考虑到的密钥长度.明文长度和密文长度问题.明文长度需要小于密钥长度,而密文长度则等 ...

  9. Js高级程序设计~读书笔记

    1.函数-函数声明和函数表达式 解析器在向执行环境加载数据时,函数声明和函数表达式的对待不同. 解析器会率先执行函数声明,将会在任何使用到它的地方前加载, 而对于函数表达式,只会在执行到的时候去加载: ...

  10. sqlserver存储过程分页记录

    USE [HK_ERP]GO/****** Object: StoredProcedure [dbo].[GetPageBillsByShopID] Script Date: 2018/10/30 1 ...