ModuleNotFoundError:在Mac OS上安装后没有名为“tensorflow”的模块

时间:2017-10-16 21:10:39

标签: tensorflow pip virtualenv macos-sierra python-3.6

我已按照https://www.tensorflow.org/install/install_mac上的安装说明进行操作 对于Tensorflow virtualenv(推荐)。

pip3 install --upgrade virtualenv 
virtualenv --system-site-packages -p python3

没有错误消息,安装很轻松。

我激活tensorflow并移动到另一个目录,以避免在将tensorflow导入Python时与tensorflow目录名混淆。结果是:

source ~/tensorflow/bin/activate
(tensorflow) Pers-MacBook-Pro:Documents per$ python3
Python 3.6.3 (default, Oct  4 2017, 06:09:15) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'

有什么问题?我在MacOS Sierra上。我运行了诊断脚本tf_env_collect.sh以提供有关环境的更多信息:

== check pips ===================================================
numpy (1.13.3)
protobuf (3.4.0)
tensorflow (1.3.0)
tensorflow-tensorboard (0.1.8)

== check for virtualenv =========================================
True

== tensorflow import ============================================
tf.VERSION = 1.3.0
tf.GIT_VERSION = v1.3.0-rc2-20-g0787eee
tf.COMPILER_VERSION = v1.3.0-rc2-20-g0787eee
Sanity check: array([1], dtype=int32)

== env ==========================================================
LD_LIBRARY_PATH is unset
DYLD_LIBRARY_PATH is unset

== nvidia-smi ===================================================
./tf_env_collect.sh: line 105: nvidia-smi: command not found

== cuda libs  ===================================================

1 个答案:

答案 0 :(得分:1)

我找到了原因:TensorFlow需要Python包,Apple默认的Python安装中包含的版本太旧了。

解决方案:使用当前版本的6升级Python安装:

$ sudo easy_install -U six