【发布时间】:2017-04-30 13:16:43
【问题描述】:
我在没有安装 anaconda 的情况下使用“使用本机 pip 安装”安装了张量流,并且能够在从终端启动的 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 notebook 中运行了相同的代码,它显示了。 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
我该如何解决这个问题?
【问题讨论】:
-
你是如何运行 jupyter notebook 的?
-
只需在终端中运行“jupyter notebook”即可。
-
我认为你的 jupyter 是用 pip3(python3) 安装的,而 tensorflow 是用 pip(python2) 安装的
-
安装的jupyter版本是python2.7。这是图像。 i.stack.imgur.com/a9mzS.png
-
另外我建议不要太熟悉 jupyter 和 tensorflow。当您使用带有 tensorflow 的 GPU 时,TF 会贪婪地将所有内存分配给所有可见的 GPU(使用
CUDA_VISIBLE_DEVICESenv 变量)。在 jupyter 中,GPU 分配将保持不变,直到您重新启动 Jupyter 内核。在你自己的机器上用一个 GPU 没什么大不了的。但是尝试在共享机器、多个 GPU 上运行您的代码……很容易让 GPU 完全分配/意外锁定。我建议这里的每个人都从命令行脚本而不是 jupyter 运行 TF 操作。
标签: python tensorflow jupyter