【问题标题】:Jupyter notebook can not import module installed in the same environmentJupyter notebook 无法导入安装在同一环境中的模块
【发布时间】:2017-11-13 17:19:33
【问题描述】:

我已经使用 conda 创建了一个虚拟环境,然后我在这个环境中安装了 tensorflow。我可以在运行交互式 python shell 时导入它。但是,我无法在 jupyter notebook 中导入 tensorflow 模块。

【问题讨论】:

  • jupyter notebook 安装在哪里?
  • 安装在全局环境中

标签: tensorflow jupyter-notebook conda virtual-environment


【解决方案1】:

您需要将 Jupyter 安装到相同的环境中。使用 tensorflow 激活环境并:

conda install jupyter 

确保您使用相应的 jupyter 开头:

python -m jupyter notebook

【讨论】:

    【解决方案2】:

    您的机器上可能安装了两个 python。运行笔记本时,运行以下命令:

    import sys
    print(sys.path)
    

    然后

    import os
    print(os.environ['PATH'])
    print(os.environ['PYTHONPATH'])
    

    确保它们指向您安装 tensorflow 的位置。您可以通过从命令行运行来检查安装 tensorflow 的位置:

    pip show -f tensorflow
    

    或者从 shell 运行:

    import tensorflow 
    tensorflow.__file__
    

    【讨论】:

      【解决方案3】:

      正如大卫所说,你可能在你的机器上安装了两个 python, 从终端和笔记本的环境中检查sys.path,理想情况下,它们应该指向您的本地环境。 要在本地环境中使用 jupyter notebook,请安装它并使用运行内核 python -m jupyter notebook

      【讨论】:

        猜你喜欢
        • 2018-11-29
        • 1970-01-01
        • 2022-08-21
        • 1970-01-01
        • 2019-06-04
        • 1970-01-01
        • 1970-01-01
        • 2019-11-06
        • 2020-02-21
        相关资源
        最近更新 更多