简体   繁体   中英

Fail to import watermark from jupyter notebook with anaconda

I see I have watermark installed:

(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) ➜  ~

I then run jupyter notebook it starts up:

(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

But when I run in jupyter I can't import watermark, anything i'm doing wrong?

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'
#Step 1: In teminal

conda install -c conda-forge watermark

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

You try to use %load_ext watermark ? Apparently the use of the library watermark is done with the magic commands from jupyter.

See: watermark github rapository

The watermark line magic can be installed by executing

pip install watermark

Alternatively, you can install the latest development version directly from GitHub via

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM