最近因为特殊的原因重新安装了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. LeetCode解题录-1~50

    [leetcode]1. Two Sum两数之和 Two Pointers, HashMap Easy [leetcode]2. Add Two Numbers两数相加 Math, LinkedLis ...

  2. laravel5增删改查

    路由规则: 数据库配置: config/database.php laravel5/.env 控制器: 表单: 展示页面: 修改页面:

  3. Redis分布式缓存

    Redis 主 slave 数据库优化-- 加inex, 分区 JVM调优--参数设置,比如偏向于计算的如何设置? 线程池:queue放满了之后,有什么方式能让他不拒绝掉?blockqueue就等在那 ...

  4. node.js的Promise库-bluebird示例

    前两天公司一哥们写了一段node.js代码发给我,后面特意提了一句“写的不太优雅”.我知道,他意思是回调嵌套回调,因为当时比较急也就没有再纠结.然而内心中总记得要解决这个问题.解决node.js的回调 ...

  5. 生成二维码、条形码、带logo的二维码

    Nuget安装ZXing.Net,帮助类: using System; using System.Collections.Generic; using System.Drawing; using Sy ...

  6. python+selenium,打开浏览器时报selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

    有一年多没写web自动化了,今天搭建环境的时候报了一个常见错误,但是处理过程有点闹心,报错就是常见的找不到驱动<selenium.common.exceptions.WebDriverExcep ...

  7. angular4模块中标签添加背景图

    一.现象 一个全屏的“走马灯”每项需要添加背景图,在循环标签里需要动态添加行内样式 二.解决 1.首先有一个图片数组,如: export class AppComponent { array = [& ...

  8. 内嵌圆角CSS实现

    前言 开发项目时,经常会遇到如上图左上角和右上角这种内嵌的圆角效果,在以前css3还没有普及时不用说一张图片搞定,但是到现在我们完全可以用css去实现. 实现 第一步:思路 仔细观察这个小缺角,它其实 ...

  9. 【Python】【BugList12】python自带IDLE执行print(req.text)报错:UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 93204-93204

    [代码] # -*- coding:UTF-8 -*- import requests if __name__ == '__main__': target = 'https://unsplash.co ...

  10. java 项目相关 学习记录

    一位资深程序员大牛给予Java初学者的学习路线建议  [任何时期都可以好好看看] https://www.imooc.com/article/8993 https://www.jianshu.com/ ...