mac上安装Tensorflow, python 3 遇到AttributeError: module ‘tensorflow’ has no attribute ‘constant’, 查找了很多资料发现还是不对,最后找到
https://qiita.com/tom_ato/items/bbdf4574b3ecb0048fa1
解决了问题,如果你之前已经安装过tensorflow, python3, 先不需要按照上面的steps来操作,可以直接执行如下命令:
$ sudo easy_install pip
$ sudo easy_install --upgrade six
$ sudo pip install --upgrade pip
$ pip3 install --upgrade tensorflow
看能不能解决你的问题,如果不能解决,你再按照上面链接中的steps来操作,
最后通过如下代码验证:
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
如果正常输出:“Hello, TensorFlow!” 说明安装TensorFlow成功!
如果出现下面错误:
2019-03-20 17:34:06.194714: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
说明你的CPU的不符合要求,可以暂时不用care, 依然继续执行命令,输出“Hello, TensorFlow!”依然能够成功!
MacBook-Pro:~ Vino$ python3
Python 3.7.1 (default, Dec 14 2018, 13:28:58)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2019-03-20 17:34:06.194714: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>>
如果想解决上面的问题,可以参照:
https://stackoverflow.com/questions/47068709/your-cpu-supports-instructions-that-this-tensorflow-binary-was-not-compiled-to-u
我试了以下命令:
pip install --ignore-installed --upgrade "Download URL"
Download URL 替换成你的下载的URL,从下面链接中找到符合你系统要求的:
https://github.com/lakshayg/tensorflow-build