【问题标题】:Something wrong with my conda channel and leads to a tensorflow import error我的 conda 通道出现问题并导致 tensorflow 导入错误
【发布时间】:2020-07-07 14:30:34
【问题描述】:

我用python 3.6venv 创建了一个Conda 环境并激活了它。然后安装tensorflow

pip install tensorflow

但是,我的 python 出了点问题。基本上就像我运行python 时一样:

Python 3.6.2 |Anaconda, Inc.| (default, Oct  5 2017, 07:59:26) [GCC 7.2.0] on linux
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'

但是python3.6 一切正常:

Python 3.6.10 | packaged by conda-forge | (default, Apr 24 2020, 16:44:11) [GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> 

我基本上想在命令行中输入“python”并与 tensorFlow 一起正常工作。

【问题讨论】:

    标签: python python-3.x tensorflow conda


    【解决方案1】:

    你这样做的方式真的很奇怪,你不应该在你的环境之上需要一个 venv,你应该使用 conda 而不是 pip install 安装 tensorflow(因为 conda 是一个环境管理器并解决了让所有软件包一起工作,而 pip 可能会以破坏整个环境解决方案的方式安装或卸载东西;tldr,更有可能工作)。尝试创建一个新环境,看看效果如何

    conda create -n tfenv tensorflow=2
    

    如果您想要 Python 3.6(另一个将使用与 tensorflow 配合使用的最新 python,应该是 3.7)

    conda create -n tfenv python=3.6 tensorflow=2
    

    然后,像往常一样激活环境

    conda activate tfenv
    

    【讨论】:

    • 您好安德鲁,感谢您的回答。我试过这个,但是它安装了 1.13 版的 tensorflow。我可以做些什么来使用 tf2.2(最新版本)吗?
    • @Zhihua 奇怪,tf2 应该是默认的(它在我的),也许你需要用 conda update conda 和 conda update anaconda 更新你的 conda。您还可以使用 conda create -n tfenv tensorflow=2 确保它会为您提供 tensorflow 2
    猜你喜欢
    • 2019-07-11
    • 2017-11-04
    • 2021-05-16
    • 2018-05-23
    • 2019-04-11
    • 2017-08-30
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多