【问题标题】:Cannot import tensorflow to python 3.5 (imports successfully in 2.7)无法将 tensorflow 导入 python 3.5(在 2.7 中成功导入)
【发布时间】:2018-07-18 12:29:41
【问题描述】:

请帮忙

我可以在 python 2.7 中导入 tensorflow,但在导入 python 3.5 时失败:ImportError: No module named 'tensorflow'

{pip show tensorflow} 命令显示如下:

名称:张量流 版本:1.9.0 总结:TensorFlow 是一个适合所有人的开源机器学习框架。 主页:https://www.tensorflow.org/ 作者:谷歌公司 作者邮箱:opensource@google.com 许可证:Apache 2.0 位置:/usr/local/lib/python2.7/dist-packages 需要:setuptools、astor、protobuf、gast、enum34、6、wheel、absl-py、backports.weakref、tensorboard、termcolor、numpy、grpcio、mock 要求:

【问题讨论】:

  • pip3 install tensorflow 会将 tensorflow 包安装到 python3 目录。如果它在 python2.7 中导入,那是因为你可能做了pip install tensorflow 将它安装到 python2.7 目录-
  • 注意pip show中的/usr/local/lib/python2.7,告诉你它显示的是为python 2.7而不是3.5安装的版本

标签: python tensorflow importerror


【解决方案1】:

可以使用以下方式安装tensorflow:

pip3 install --upgrade tensorflow

或者使用 anaconda:

conda create -n tensorflow pip python=3.5
activate tensorflow
pip install --ignore-installed --upgrade tensorflow 

取自here

【讨论】:

    【解决方案2】:

    适用于 Python 3.7 版本的 Anaconda 2019.03

    CPU

    创建命令:

    conda create -n tensorflow_env tensorflow

    激活命令:

    conda 激活 tensorflow_env

    导入命令:

    (tensorflow_env) C:\WINDOWS\system32>python

    将张量流导入为 tf

    打印(tf.版本

    GPU

    创建命令:

    conda create -n tensorflow_gpuenv tensorflow-gpu

    激活命令:

    conda 激活 tensorflow_gpuenv

    导入命令:

    (tensorflow_gpuenv) C:\WINDOWS\system32>python

    将张量流导入为 tf

    打印(tf.版本

    【讨论】:

      猜你喜欢
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      • 2019-07-06
      • 2011-04-29
      • 2015-09-13
      • 2013-02-27
      • 1970-01-01
      相关资源
      最近更新 更多