【问题标题】:I can't import tensorflow in jupyterlab, although I can import tensorflow in anaconda prompt我无法在 jupyterlab 中导入 tensorflow,尽管我可以在 anaconda 提示符中导入 tensorflow
【发布时间】:2019-06-14 15:35:22
【问题描述】:

在 anaconda 提示符下,我可以导入 tensorflow,但无法在 jupyterlab 中导入 tensorflow。

我今天下载了anaconda,打开了anaconda prompt。 然后我做了

   python -m pip install --upgrade pip

.

   conda create -n tensorflow python=3.6

.

   activate tensorflow

.

   pip install tensorflow

.

   python

.

   import tensorflow as tf

.

   tf.__version__

在这个过程中没有任何错误。

于是我打开了jupyterlab并写了

 import tensorflow as tf

但是没有用。

在 anaconda 提示符下,我能够像下面的代码一样导入 tensorflow。

 (base) C:\Users\SuperNoteJ>activate tensorflow

 (tensorflow) C:\Users\SuperNoteJ>python
 Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 18:50:55) [MSC v.1915 64 bit (AMD64)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import tensorflow as tf
 >>> tf.__version__
 '1.12.0'
 >>>

但是当我打开 anaconda navigator 并启动 jupyterlab(使用 base) 我无法导入张量流。 以下代码是jupyterlab上的错误代码。

 import tensorflow as tf
 -----------------------------------------------------------------------
 ModuleNotFoundError                       Traceback (most recent call last)
 <ipython-input-1-64156d691fe5> in <module>
 ----> 1 import tensorflow as tf

 ModuleNotFoundError: No module named 'tensorflow'

【问题讨论】:

    标签: tensorflow anaconda jupyter-lab


    【解决方案1】:

    我认为您无法导入 tensorflow 的原因是因为您没有处于正确的环境中。如果 tensorflow 安装在“tensorflow”环境中,您需要从该环境中启动 jupyter lab,或者在 jupyter lab 中选择该环境中的内核。

    如果您对后者感兴趣,我会参考这个主题 (https://stackoverflow.com/a/53546634/10511793),了解如何使用在基础环境中启动的 jupyter 实验室的另一个环境。

    【讨论】:

      猜你喜欢
      • 2018-06-02
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      • 2019-05-17
      • 2020-01-10
      • 2020-06-17
      相关资源
      最近更新 更多