Jupyter Notebook load_ext signature

时间:2016-02-16 18:14:04

标签: python import jupyter-notebook

前段时间我发现了以下website,我从中复制了源代码并将其粘贴到我自己的jupyter notebook中。

%load_ext signature
%matplotlib inline

import requests
import helpers

import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt

from lxml import html
from datetime import datetime

# Set style and meta info.
mpl.style.use('ramiro')
url = 'https://en.wikipedia.org/wiki/Wikipedia:Database_reports/Pages_with_the_most_revisions'
end_date = '27 March 2015'
chartinfo = 'Author: Ramiro Gómez - ramiro.org • Data: ' + url.replace('https://', '')
infosize = 12

# Extract first wikitable from page
xpath = '//*[contains(@class, "wikitable")]'
tree = html.fromstring(requests.get(url).text)
table = tree.xpath(xpath)[0]
raw_html = html.tostring(table)

# Create dataframe from html table
df = pd.read_html(raw_html, header=0, index_col='Page')[0]
df.index = df.index.map(lambda x: x.replace('_', ' '))
df.head(10)

现在我重新发现了这款笔记本,想要运行它。但是,它不起作用:

ImportError                               Traceback (most recent call last)
<ipython-input-1-cd5561f41831> in <module>()
----> 1 get_ipython().magic('load_ext signature')
    2 get_ipython().magic('matplotlib inline')
    3 
    4 import requests
    5 import helpers

    /home/xiaolong/development/anaconda3/envs/jupyter/lib/python3.5/site-packages/IPython/core/interactiveshell.py in   magic(self, arg_s)
2161         magic_name, _, magic_arg_s = arg_s.partition(' ')
2162         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2163         return self.run_line_magic(magic_name, magic_arg_s)
2164 
2165     #-------------------------------------------------------------------------

/home/xiaolong/development/anaconda3/envs/jupyter/lib/python3.5/site-packages/IPython/core/interactiveshell.py in   run_line_magic(self, magic_name, line)
2082                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2083             with self.builtin_trap:
-> 2084                 result = fn(*args,**kwargs)
2085             return result
2086 

<decorator-gen-64> in load_ext(self, module_str)

/home/xiaolong/development/anaconda3/envs/jupyter/lib/python3.5/site-packages/IPython/core/magic.py in <lambda>(f, *a,  **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
    --> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

    /home/xiaolong/development/anaconda3/envs/jupyter/lib/python3.5/site-packages/IPython/core/magics/extension.py in   load_ext(self, module_str)
    64         if not module_str:
    65             raise UsageError('Missing module name.')
    ---> 66         res = self.shell.extension_manager.load_extension(module_str)
    67 
    68         if res == 'already loaded':

    /home/xiaolong/development/anaconda3/envs/jupyter/lib/python3.5/site-packages/IPython/core/extensions.py in     load_extension(self, module_str)
    82             if module_str not in sys.modules:
    83                 with prepended_to_syspath(self.ipython_extension_dir):
    ---> 84                     __import__(module_str)
    85             mod = sys.modules[module_str]
    86             if self._call_load_ipython_extension(mod):

    ImportError: No module named 'signature'

我不知道为什么这个模块丢失或实际上是什么。

如何解决此问题并使代码运行?

其他信息:

我在虚拟环境中拥有jupyter笔记本,其中包含以下软件包:

# packages in environment at /home/xiaolong/development/anaconda3/envs/jupyter:
#
abstract-rendering        0.5.1               np110py35_0    defaults
alabaster                 0.7.7                    py35_0    defaults
anaconda                  2.5.0               np110py35_0    defaults
anaconda-client           1.2.2                    py35_0    defaults
argcomplete               1.0.0                    py35_1    defaults
astropy                   1.1.1               np110py35_0    defaults
atlas                     0.27.0                    <pip>
babel                     2.2.0                    py35_0    defaults
beautifulsoup4            4.4.1                    py35_0    defaults
bitarray                  0.8.1                    py35_0    defaults
blaze                     0.9.0                     <pip>
blaze-core                0.9.0                    py35_0    defaults
bokeh                     0.11.0                   py35_0    defaults
boto                      2.39.0                   py35_0    defaults
bottleneck                1.0.0               np110py35_0    defaults
brewer2mpl                1.4.1                     <pip>
calysto-prolog            0.8.3                     <pip>
cffi                      1.2.1                    py35_0    defaults
clyent                    1.2.0                    py35_0    defaults
colorama                  0.3.6                    py35_0    defaults
configobj                 5.0.6                    py35_0    defaults
cryptography              1.0.2                    py35_0    defaults
curl                      7.45.0                        0    defaults
cycler                    0.9.0                    py35_0    defaults
cython                    0.23.4                   py35_0    defaults
cytoolz                   0.7.5                    py35_0    defaults
datashape                 0.5.0                    py35_0    defaults
decorator                 4.0.6                    py35_0    defaults
docutils                  0.12                     py35_0    defaults
dynd                      f641248                   <pip>
dynd-python               0.7.1                    py35_0    defaults
emcee                     2.1.0                     <pip>
et-xmlfile                1.0.1                     <pip>
et_xmlfile                1.0.1                    py35_0    defaults
fastcache                 1.0.2                    py35_0    defaults
flask                     0.10.1                   py35_1    defaults
fontconfig                2.11.1                        5    defaults
freetype                  2.5.5                         0    defaults
futures                   3.0.3                    py35_0    defaults
ggplot                    0.6.8                     <pip>
gmpy2                     2.0.7                     <pip>
greenlet                  0.4.9                    py35_0    defaults
h5py                      2.5.0               np110py35_4    defaults
hdf5                      1.8.15.1                      2    defaults
idna                      2.0                      py35_0    defaults
ipykernel                 4.2.2                    py35_0    defaults
ipython                   4.1.1                    py35_0    defaults
ipython-genutils          0.1.0                     <pip>
ipython-notebook          4.0.4                    py35_0    defaults
ipython-qtconsole         4.0.1                    py35_0    defaults
ipython_genutils          0.1.0                    py35_0    defaults
ipywidgets                4.1.1                    py35_0    defaults
itsdangerous              0.24                     py35_0    defaults
jbig                      2.1                           0    defaults
jdcal                     1.2                      py35_0    defaults
jedi                      0.9.0                    py35_0    defaults
jinja2                    2.8                      py35_0    defaults
jpeg                      8d                            0    <unknown>
jsonschema                2.4.0                    py35_0    defaults
jupyter                   1.0.0                    py35_1    defaults
jupyter-client            4.1.1                     <pip>
jupyter-console           4.1.0                     <pip>
jupyter-core              4.0.6                     <pip>
jupyter-kernel-test       0.1                       <pip>
jupyter_client            4.1.1                    py35_0    defaults
jupyter_console           4.1.0                    py35_0    defaults
jupyter_core              4.0.6                    py35_0    defaults
libdynd                   0.7.1                         0    defaults
libffi                    3.0.13                        0    <unknown>
libgfortran               1.0                           0    defaults
libpng                    1.6.17                        0    <unknown>
libsodium                 1.0.3                         0    defaults
libtiff                   4.0.6                         1    defaults
libxml2                   2.9.2                         0    <unknown>
libxslt                   1.1.28                        0    <unknown>
llvmlite                  0.8.0                    py35_0    defaults
lmfit                     0.8.2                     <pip>
lxml                      3.5.0                    py35_0    defaults
markupsafe                0.23                     py35_0    defaults
matplotlib                1.5.1               np110py35_0    defaults
metakernel                0.11.5                    <pip>
metakernel-bash           0.11.3                    <pip>
mistune                   0.7.1                    py35_0    defaults
mkl                       11.3.1                        0    defaults
mkl-service               1.1.2                    py35_0    defaults
multipledispatch          0.4.8                    py35_0    defaults
nbconvert                 4.1.0                    py35_0    defaults
nbformat                  4.0.1                    py35_0    defaults
networkx                  1.11                     py35_0    defaults
nltk                      3.1                      py35_0    defaults
nose                      1.3.7                    py35_0    defaults
notebook                  4.1.0                    py35_0    defaults
numba                     0.23.1              np110py35_0    defaults
numexpr                   2.4.6               np110py35_1    defaults
numpy                     1.10.4                   py35_0    defaults
octave-kernel             0.13.2                    <pip>
odo                       0.4.0                    py35_0    defaults
openblas                  0.2.14                        3    defaults
openpyxl                  2.3.2                    py35_0    defaults
openssl                   1.0.2f                        0    defaults
pandas                    0.17.1              np110py35_0    defaults
patchelf                  0.8                           0    defaults
path.py                   8.1.2                    py35_1    defaults
patsy                     0.4.0               np110py35_0    defaults
pep8                      1.7.0                    py35_0    defaults
pexpect                   3.3                      py35_0    defaults
pickleshare               0.5                      py35_0    defaults
pillow                    3.1.0                    py35_0    defaults
pip                       8.0.2                    py35_0    defaults
ply                       3.8                      py35_0    defaults
psutil                    3.4.2                    py35_0    defaults
ptyprocess                0.5                      py35_0    defaults
py                        1.4.31                   py35_0    defaults
pyaml                     15.8.2                    <pip>
pyasn1                    0.1.9                    py35_0    defaults
pycosat                   0.6.1                    py35_0    defaults
pycparser                 2.14                     py35_0    defaults
pycrypto                  2.6.1                    py35_0    defaults
pycurl                    7.19.5.3                 py35_0    defaults
pyflakes                  1.0.0                    py35_0    defaults
pygments                  2.1                      py35_0    defaults
pymatbridge               0.5.2                     <pip>
pyopenssl                 0.15.1                   py35_1    defaults
pyparsing                 2.0.3                    py35_0    defaults
pyqt                      4.11.4                   py35_1    defaults
pytables                  3.2.2               np110py35_0    defaults
pytest                    2.8.5                    py35_0    defaults
python                    3.5.1                         0    defaults
python-contrib-nbextensions alpha                     <pip>
python-dateutil           2.4.2                    py35_0    defaults
pytz                      2015.7                   py35_0    defaults
pyyaml                    3.11                     py35_1    defaults
pyzmq                     15.2.0                   py35_0    defaults
qt                        4.8.7                         1    defaults
qtconsole                 4.1.1                    py35_0    defaults
readline                  6.2                           2    <unknown>
redis                     2.6.9                         0    <unknown>
redis-py                  2.10.3                   py35_0    defaults
requests                  2.9.1                    py35_0    defaults
rope                      0.9.4                    py35_1    defaults
rope-py3k                 0.9.4.post1               <pip>
satlas                    0.1.0b17                  <pip>
scikit-image              0.11.3              np110py35_0    defaults
scikit-learn              0.17                np110py35_2    defaults
scipy                     0.17.0              np110py35_1    defaults
setuptools                19.6.2                   py35_0    defaults
simplegeneric             0.8.1                    py35_0    defaults
sip                       4.16.9                   py35_0    defaults
six                       1.10.0                   py35_0    defaults
snowballstemmer           1.2.1                    py35_0    defaults
sockjs-tornado            1.0.1                    py35_0    defaults
sphinx                    1.3.5                    py35_0    defaults
sphinx-rtd-theme          0.1.9                     <pip>
sphinx_rtd_theme          0.1.9                    py35_0    defaults
spyder                    2.3.8                    py35_0    defaults
spyder-app                2.3.8                    py35_0    defaults
sqlalchemy                1.0.11                   py35_0    defaults
sqlite                    3.9.2                         0    defaults
statsmodels               0.6.1               np110py35_0    defaults
sympy                     0.7.6.1                  py35_0    defaults
tables                    3.2.2                     <pip>
terminado                 0.5                      py35_1    defaults
threadpool                1.3.2                     <pip>
tk                        8.5.18                        0    <unknown>
toolz                     0.7.4                    py35_0    defaults
tornado                   4.3                      py35_0    defaults
tqdm                      3.8.0                     <pip>
traitlets                 4.1.0                    py35_0    defaults
unicodecsv                0.14.1                   py35_0    defaults
util-linux                2.21                          0    <unknown>
werkzeug                  0.11.3                   py35_0    defaults
wheel                     0.29.0                   py35_0    defaults
xlrd                      0.9.4                    py35_0    defaults
xlsxwriter                0.8.4                    py35_0    defaults
xlwt                      1.0.0                    py35_0    defaults
xz                        5.0.5                         1    defaults
yaml                      0.1.6                         0    <unknown>
zeromq                    4.1.3                         0    defaults
zlib                      1.2.8                         0    <unknown>

2 个答案:

答案 0 :(得分:4)

我也面对这个问题,做了一点探索,并解决了它。

请阅读%load_ext magic。显然signature是一个扩展,要使用它,您需要先安装它。

现在问题是你需要找到签名代码。

我花了更长的时间才找到代码。该教程由RamiroGómez编写,我在github and the script找到了他的网页。

要安装,您可以在iPython shell中使用%install_ext magic。

答案 1 :(得分:0)

安装:

EbmlConfig.cmake

创建文件“ signature.py”->链接Ramiro Gómez's script并将其添加到您的文件夹中。做完了!