【问题标题】:Running “import tensorflow” on Mac generates "No module named tensorflow" error在 Mac 上运行“import tensorflow”会产生“No module named tensorflow”错误
【发布时间】:2018-09-02 17:09:26
【问题描述】:

其实我已经通过使用安装了tensorflow

$ pip install tensorflow

当我使用它时效果很好

$ python
Python 2.7.15 (default, Jul 23 2018, 21:27:06) 
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>import tensorflow
>>>

但是当我在命令行上使用 python3 时

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) 
[Clang 6.0 (clang-600.0.57)] on darwin
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'
>>> 

它显示一个错误,当我使用 IDLE 时它显示相同的错误

【问题讨论】:

  • 对于python3,做pip3 install tensorflow
  • pip3 install tensorflow
  • 好吧,看来我应该使用$ pip3 install tensorflow,但是我的pip3还有一个问题,让我先尝试解决这个问题......
  • 尚不支持 Python 3.7,请查看此线程,[stackoverflow.com/questions/51337939/…
  • 您可能在“pip3 install tensorflow”命令中遇到以下错误,“找不到满足要求 tensorflow 的版本(来自版本:)” - 同样不支持此版本的 Python

标签: python macos tensorflow


【解决方案1】:

使用

pip3 install tensorflow

pip 安装到默认的 python 目录。 pip3 安装到 python3

【讨论】:

    猜你喜欢
    • 2017-06-20
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 2014-07-17
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 2016-04-27
    相关资源
    最近更新 更多