tensorflow能在终端运行,也能在通过终端打开的pycharm上运行,就是不能在直接打开的pycharm上运行,一运行就跳到下图界面
然后看运行窗口的出错信息,点击最右边的view,发现缺少个文件,如代码所示
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/lib/python3.6/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.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.10.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.
1.先上一段测试代码
import tensorflow as tf
hello = tf.constant('hello,tensorflow')
sess=tf.Session()
print(sess.run(hello))
新建立的文件可能在import tensorflow as tf
的时候,没有tensorflow提示,也就是导入失败,这就需要第一步配置,配置如下:
然后点击Apply, OK即可
在菜单栏,选择 Run --> Edit Configurations
在右侧的框里,找到Environment
点击Environment variables
右侧的小文件夹
点击+
,在Name添加LB_LIBRARY_PATH
,在Value处添加 你安装的cuda的lib64路径,你可以在终端输入gedit ~/.bashrc
进行查看,其实就是你在安装cuda时添加的环境变量
直接复制LD_LIBRARY_PATH处的/usr/local/cuda-10.0/lib64
即可,配置完后的图片
然后再运行,就可以正常运行了。
TensorFlow可以在终端和通过终端打开的PyCharm中运行,不能在直接打开的PyCharm中运行
原文:https://www.cnblogs.com/youpeng/p/10887413.html