如题
sudo -H pip3 install tensorflow
安装成功,不成功可能是各种依赖库没有装或者版本没对上。
执行python3命令
~$ python3
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
>>> quit()
结果一看,这里面python3的版本和TensorFlow 安装时打印信息显示的版本(python3.4)不一致,好吧,应该是装在python3.4上的。这里估计是anaconda 安装后,搞混了。
直接在命令行输入:
~$ python3.4
Python 3.4.3 (default, Nov 12 2018, 22:25:49)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> import tensorflow as tf
>>> hello = tf.constant('Hello,world!')
>>> sess = tf.Session()
2019-01-12 04:18:42.349465: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
>>> result = sess.run(hello)
>>> sess.close()
>>> print(result)
b'Hello,world!'
>>> quit()
这样就可以了,注意版本问题。
其他问题可以看看:
ubuntu 下安装完tensorflow 后 import 提示 no module named tensorflow