【问题标题】:Tensorflow Module not found on Mac在 Mac 上找不到 Tensorflow 模块
【发布时间】:2019-01-10 04:40:08
【问题描述】:

我在带有 High Sierra 的 Macbook Pro 上使用默认版本的 Python(2.7)。我已经使用以下命令安装了默认版本的 tensorflow,即 1.9:

pip -V
>>>pip 18.0 from /usr/local/lib/python2.7/site-packages/pip-18.0-py2.7.egg/pip (python 2.7)

pip install tensorflow
pip list

>>>tensorflow 1.9.0

然后我启动 python:

python
Python 2.7.10 (default, Oct  6 2017, 22:29:07) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

然后我尝试导入 tensorflow 并得到这个错误:

>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named tensorflow
>>>

我多次尝试按照说明进行操作,但均未成功。我会很感激任何帮助。谢谢。

【问题讨论】:

  • 你用什么来运行你的代码?空闲?,间谍?皮查姆?终端? ...
  • 我使用的是mac终端。
  • 你有没有使用Anaconda加载某个版本的python?
  • Python 3 已经推出 10 年了,为什么还要使用 Apple 发布的古老的 Python 2.7?
  • @jmh 我的机器上有 Anaconda,它工作正常。我需要非 anaconda 环境来实现 Python 和 R 之间的连接。

标签: macos python-2.7 tensorflow


【解决方案1】:

当您安装 tensorflow 时,它可能与不同版本的 python 相关联。我建议你在虚拟环境中运行。创建一个虚拟环境并激活它。然后一旦激活运行pip install tensorflow,然后尝试在您的虚拟环境仍然激活的情况下运行您的代码。

This link 更好地描述了为什么需要虚拟环境以及如何安装它们。

【讨论】:

  • 感谢您的意见。它有效,事实证明问题出在其他地方。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-01
  • 2019-02-09
  • 1970-01-01
  • 1970-01-01
  • 2018-09-11
  • 2017-01-22
相关资源
最近更新 更多