2

在 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)时,我无法导入 tensorflow。以下代码是 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'
4

1 回答 1

1

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

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

于 2019-01-21T09:27:27.173 回答