我用pip3安装了tensorflow,然后用它验证了它
# Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
终端一切正常。但是,当我尝试在Anaconda中导入tensorflow时,它会抛出一个错误:
import tensorflow as tf
Traceback (most recent call last):
File "<ipython-input-4-64156d691fe5>", line 1, in <module>
import tensorflow as tf
File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/Users/Ivan/anaconda3/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 "/Users/Ivan/anaconda3/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/Users/Ivan/anaconda3/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: dlopen(/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 10): Library not loaded: @rpath/libcublas.8.0.dylib
Referenced from: /Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
Reason: image not found
Failed to load the native TensorFlow runtime.
我尝试了一些我在互联网上找到的东西,这就是我得到的:
conda update --all
我得到“conda:command not found”。在终端和Anaconda提示也。但如果在终端我输入
zsh
conda info
有用我正在使用OS X Sierra和Anaconda 4.4.10。我该如何处理这个问题?我对终端只有基本的了解。
从“开始”菜单中搜索Anaconda Prompt。右键单击它并选择以管理员身份运行。在打开的终端中,键入:
conda install tensorflow
这对我有用。
谢谢大家的意见。这是我最终解决问题的方法:
这些步骤让我开始工作张量流,但我不确定它们中的每一个是否都是关键的。
1)我确保我的zsh配置文件正常工作。似乎它以某种方式不知道conda已安装,我用PATH=~/anaconda3/bin:$PATH
导出到~/.zshrc
文件解决了它。
2)我卸载了错误版本的tensorflow(使用gpu支持)并更新了所有内容(Anaconda,python,pip等)。
3)然后我按照这里专门针对Anaconda安装https://www.tensorflow.org/install/install_mac#the_url_of_the_tensorflow_python_package的指示创建了虚拟环境(我完全为python 3.6创建了环境,以前我不假思索地只使用了python 3.3来自示例,我的不好)。
4)我在Spyder中选择了这个环境 - 一切正常。