无法从带有anaconda的jupyter笔记本导入水印

时间:2018-01-30 18:24:52

标签: python anaconda jupyter-notebook jupyter

我看到我安装了水印:

(testenv) ➜  ~ conda install watermark
Fetching package metadata ...........
Solving package specifications: .

# All requested packages already installed.
# packages in environment at /Users/myuser/anaconda3/envs/testenv:
#
watermark                 1.5.0                    py36_0    conda-forge
(testenv) ➜  ~

然后我开始运行jupyter notebook

(testenv) ➜  ~ jupyter notebook
[I 11:30:56.897 NotebookApp] JupyterLab alpha preview extension loaded from /Users/myuser/anaconda3/lib/python3.6/site-packages/jupyterlab
JupyterLab v0.27.0
Known labextensions:
[I 11:30:56.899 NotebookApp] Running the core application with no additional extensions or settings
[I 11:30:56.905 NotebookApp] Serving notebooks from local directory: /Users/myuser
[I 11:30:56.905 NotebookApp] 0 active kernels
[I 11:30:56.905 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=a17e10f9a22d9bbee4bc55d24741c56408278254edb57a22
[I 11:30:56.905 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 11:30:56.909 NotebookApp]

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=a17e10f9a22d9bbee4bc55d24741c56408278254edb57a22
[I 11:30:57.152 NotebookApp] Accepting one-time-token-authenticated connection from ::1

但是当我在jupyter中运行时,我无法导入水印,我做错了什么?

from __future__ import print_function
from distutils.version import LooseVersion as Version
import sys

importlib.import_module('watermark')

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-6-b1c6f1862f9d> in <module>()
      3 import sys
      4 
----> 5 importlib.import_module('watermark')

~/.pyenv/versions/3.6.4rc1/lib/python3.6/importlib/__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 
    128 

~/.pyenv/versions/3.6.4rc1/lib/python3.6/importlib/_bootstrap.py in _gcd_import(name, package, level)

~/.pyenv/versions/3.6.4rc1/lib/python3.6/importlib/_bootstrap.py in _find_and_load(name, import_)

~/.pyenv/versions/3.6.4rc1/lib/python3.6/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'watermark'

3 个答案:

答案 0 :(得分:1)

#Step 1: In teminal

conda install -c conda-forge watermark

#Step 2: In Jupyter Notebook
 import sys
 !conda install --yes --prefix {sys.prefix} watermark

答案 1 :(得分:0)

您尝试使用%load_ext watermark吗?显然,使用jupyter的magic命令可以完成库水印的使用。

请参阅:watermark github rapository

答案 2 :(得分:0)

可以通过执行安装水印线魔术

pip install watermark

或者,您可以直接从GitHub通过

安装最新的开发版本。

pip install -e git+https://github.com/rasbt/watermark#egg=watermark