我在没有安装anaconda的情况下安装了“使用原生点安装”的张量流程,并且能够从终端启动的Python控制台中导入TensorFlow。 image
$ python
Python 2.7.13 (default, Apr 4 2017, 08:47:57)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2017-04-30 20:54:36.278740: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-04-30 20:54:36.278773: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-04-30 20:54:36.278785: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-04-30 20:54:36.278794: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2017-04-30 20:54:36.423246: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:865] OS X does not support NUMA - returning NUMA node zero
2017-04-30 20:54:36.432456: I tensorflow/core/common_runtime/gpu/gpu_device.cc:887] Found device 0 with properties:
name: GeForce GTX 1080
major: 6 minor: 1 memoryClockRate (GHz) 1.86
pciBusID 0000:01:00.0
Total memory: 8.00GiB
Free memory: 6.12GiB
2017-04-30 20:54:36.432507: I tensorflow/core/common_runtime/gpu/gpu_device.cc:908] DMA: 0
2017-04-30 20:54:36.432511: I tensorflow/core/common_runtime/gpu/gpu_device.cc:918] 0: Y
2017-04-30 20:54:36.432519: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
>>> print(sess.run(hello))
Hello, TensorFlow!
>>>
但我在Jupiter笔记本中运行相同的代码并显示出来。 image
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-d7933b52e0de> in <module>()
----> 1 import tensorflow as tf
2 hello = tf.constant('Hello, TensorFlow!')
3 sess = tf.Session()
4 print(sess.run(hello))
ImportError: No module named tensorflow
我该如何解决这个问题?
答案 0 :(得分:0)
Python,Tensorflow&amp; Jupyter要么必须保存版本python2 / python3。 以下是设置jupyter&amp; amp;使用python3进行Tensorflow
sudo apt install python3-pip
pip3 install --upgrade pip ##optional
pip3 install jupyter
##Install Tensorflow
pip3 install --upgrade tensorflow
Test
$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>>
##Launch jupyter
jupyter notebook
(In Ubuntu you may need to launch ~/.local/bin/jupyter-notebook until you relaunch the bash i.e. PATH issue)
##Create new notepad and run
import tensorflow as tf