Rock It 《ML》JupyterLab 【丙】Extension《二》上

為了圖文並茂,故而想要 Jupyter 筆記本上的許多小工具呦☆

/jupyter-renderers

jupyter-renderers/packages/geojson-extension/

geojson-extension

A JupyterLab extension for rendering GeoJSON

demo

Requirements

  • JupyterLab ^0.30.0
  • Node.js >= 5

Install

sudo jupyter labextension install @jupyterlab/geojson-extension

 

誰知打算用『燈籠』

/lantern

Data exploration glue

Lantern

An orchestration layer for plots and tables, dummy datasets, widgets, research, reports, and anything else a data scientist might need.

Build Status GitHub issues Waffle.io codecov Gitter BCH compliance PyPI PyPI npm Docs

Note: Lantern Live has moved to tributary

Note: Email reports have moved to jupyterlab_email

Note: Publish is removed in favor of Voila

Install

To install the base package from pip:

pip install pylantern

To Install from source:

make install

To install the JupyterLab extension:

jupyter labextension install pylantern

or from source:

make labextension

To enable the Jupyter server extension:

jupyter serverextension enable --py lantern

Or run the corresponding commands directly

Lantern relies on JupyterLab extensions:

jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install plotlywidget
jupyter labextension install @jupyterlab/plotly-extension
jupyter labextension install jupyterlab_bokeh
jupyter labextension install qgrid
jupyter labextension install @jpmorganchase/perspective-jupyterlab
jupyter labextension install ipysheet
jupyter labextension install lineup_widget

The following are for work in-progress on master:

jupyter labextension install bqplot

……

Getting Started

Read the docs!

Data

 

照亮前行之路

sudo pip3 install pylantern

卻遭遇麻煩也☻

rock64@rock64:~ipython3 Python 3.5.3 (default, Sep 27 2018, 17:25:39)  Type 'copyright', 'credits' or 'license' for more information IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.  In [1]: import lantern as l                                                      --------------------------------------------------------------------------- ImportError                               Traceback (most recent call last) /usr/lib/python3.5/tkinter/__init__.py in <module>      35 try: ---> 36     import _tkinter      37 except ImportError as msg:  ImportError: No module named '_tkinter'  During handling of the above exception, another exception occurred:  ImportError                               Traceback (most recent call last) <ipython-input-1-b3a41b239d6b> in <module> ----> 1 import lantern as l  /usr/local/lib/python3.5/dist-packages/lantern/__init__.py in <module> ----> 1 from .plotting import plot, figure       2 from .data import *       3 from .grids import grid       4 from .utils import download       5 from .extensions import *  /usr/local/lib/python3.5/dist-packages/lantern/plotting/__init__.py in <module>       1 from six import iteritems ----> 2 from .plot_matplotlib import MatplotlibPlot       3 from .plot_plotly import PlotlyPlot       4 from .plot_bokeh import BokehPlot       5 from ..utils import LanternException  /usr/local/lib/python3.5/dist-packages/lantern/plotting/plot_matplotlib.py in <module> ----> 1 import matplotlib.pyplot as plt       2 from .plotobj import BasePlot       3 from .plotutils import align_yaxis_np, get_color       4 from ..utils import in_ipynb       5   /usr/lib/python3/dist-packages/matplotlib/pyplot.py in <module>     113      114 from matplotlib.backends import pylab_setup --> 115 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()     116      117 _IP_REGISTERED = None  /usr/lib/python3/dist-packages/matplotlib/backends/__init__.py in pylab_setup()      30     # imports. 0 means only perform absolute imports.      31     backend_mod = __import__(backend_name, ---> 32                              globals(),locals(),[backend_name],0)      33       34     # Things we pull in from all backends  /usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py in <module>       4        5 import six ----> 6 from six.moves import tkinter as Tk       7 from six.moves import tkinter_filedialog as FileDialog       8   /usr/lib/python3/dist-packages/six.py in __get__(self, obj, tp)      90       91     def __get__(self, obj, tp): ---> 92         result = self._resolve()      93         setattr(obj, self.name, result)  # Invokes __set__.      94         try:  /usr/lib/python3/dist-packages/six.py in _resolve(self)     113      114     def _resolve(self): --> 115         return _import_module(self.mod)     116      117     def __getattr__(self, attr):  /usr/lib/python3/dist-packages/six.py in _import_module(name)      80 def _import_module(name):      81     """Import module, returning the module after the last dot.""" ---> 82     __import__(name)      83     return sys.modules[name]      84   /usr/lib/python3.5/tkinter/__init__.py in <module>      36     import _tkinter      37 except ImportError as msg: ---> 38     raise ImportError(str(msg) + ', please install the python3-tk package')      39 TclError = _tkinter.TclError      40 from tkinter.constants import *  ImportError: No module named '_tkinter', please install the python3-tk package </pre>    <span style="color: #666699;">過了一關</span>  <span style="color: #ff9900;">sudo apt-get install python3-tk</span>  <span style="color: #666699;">又來一關☻</span> <pre class="lang:default decode:true ">rock64@rock64:~ ipython3
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import lantern as l                                                     
Traceback (most recent call last):

  File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 3267, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-1-b3a41b239d6b>", line 1, in <module>
    import lantern as l

  File "/usr/local/lib/python3.5/dist-packages/lantern/__init__.py", line 2, in <module>
    from .data import *

  File "/usr/local/lib/python3.5/dist-packages/lantern/data/__init__.py", line 3, in <module>
    from .other import person, people, company, companies, ticker, currency, trades, superstore

  File "/usr/local/lib/python3.5/dist-packages/lantern/data/other.py", line 4, in <module>
    import mimesis

  File "/usr/local/lib/python3.5/dist-packages/mimesis/__init__.py", line 10, in <module>
    from mimesis.providers import *

  File "/usr/local/lib/python3.5/dist-packages/mimesis/providers/__init__.py", line 5, in <module>
    from mimesis.providers.base import BaseProvider, BaseDataProvider

  File "/usr/local/lib/python3.5/dist-packages/mimesis/providers/base.py", line 84
    self._data: Dict[str, Any] = {}
              ^
SyntaxError: invalid syntax

 

當真關關難過,關關過耶?☻

/mimesis

Mimesis is fast and extremely easy to use Python package, which helps generate big volumes of fake data for a variety of purposes in a variety of languages. https://mimesis.name/

Mimesis – Fake Data Generator

https://raw.githubusercontent.com/lk-geimfari/mimesis/master/media/readme-logo.png

Description

Travi CI AppVeyor CI Documentation Status Code Coverage Package version Python version

Mimesis is fast and extremely easy to use Python package, which helps generate big volumes of fake data for a variety of purposes in a variety of languages. The fake data can be particularly useful during software development and testing. For example, it could be used to populate a testing database, create beautiful JSON and XML files, anonymize data taken from a production service and etc.

……

typingSupport for type hints

New in version 3.5.

Source code: Lib/typing.py

Note

The typing module has been included in the standard library on a provisional basis. New features might be added and API may change even between minor releases if deemed necessary by the core developers.


This module supports type hints as specified by PEP 484 and PEP 526. The most fundamental support consists of the types Any, Union, Tuple, Callable, TypeVar, and Generic. For full specification please see PEP 484. For a simplified introduction to type hints see PEP 483.

The function below takes and returns a string and is annotated as follows:

def greeting(name: str) -> str:
    return 'Hello ' + name

In the function greeting, the argument name is expected to be of type str and the return type str. Subtypes are accepted as arguments.

………

 

大膽闖關改☺!

     檔案: /usr/local/lib/python3.5/dist-packages/mimesis/providers/base.py     


    def __init__(self, locale: str = locales.DEFAULT_LOCALE,
                 seed: Seed = None) -> None:
        """Initialize attributes for data providers.

        :param locale: Current locale.
        :param seed: Seed to all the random functions.
        """
        super().__init__(seed=seed)
        self._data: Dict[str, Any] = {}
        self._datafile = ''
        self._setup_locale(locale)
        self._data_dir = Path(__file__).parent.parent.joinpath('data')

    def _setup_locale(self, locale: str = locales.DEFAULT_LOCALE) -> None:
        """Set up locale after pre-check.

        :param str locale: Locale
        :raises UnsupportedLocale: When locale is not supported.

 

self._data = {} # type is dict(str,any)

檔案: /usr/local/lib/python3.5/dist-packages/mimesis/providers/base.py    已更動


    def __init__(self, locale: str = locales.DEFAULT_LOCALE,
                 seed: Seed = None) -> None:
        """Initialize attributes for data providers.

        :param locale: Current locale.
        :param seed: Seed to all the random functions.
        """
        super().__init__(seed=seed)
        self._data = {} # type is dict(str,any)
        self._datafile = ''
        self._setup_locale(locale)
        self._data_dir = Path(__file__).parent.parent.joinpath('data')

    def _setup_locale(self, locale: str = locales.DEFAULT_LOCALE) -> None:
        """Set up locale after pre-check.

        :param str locale: Locale
        :raises UnsupportedLocale: When locale is not supported.

 

果然沒有盡頭,天不從人願乎?★

rock64@rock64:~ipython3 Python 3.5.3 (default, Sep 27 2018, 17:25:39)  Type 'copyright', 'credits' or 'license' for more information IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.  In [1]: import lantern as l                                                      --------------------------------------------------------------------------- ImportError                               Traceback (most recent call last) <ipython-input-1-b3a41b239d6b> in <module> ----> 1 import lantern as l  /usr/local/lib/python3.5/dist-packages/lantern/__init__.py in <module>       1 from .plotting import plot, figure ----> 2 from .data import *       3 from .grids import grid       4 from .utils import download       5 from .extensions import *  /usr/local/lib/python3.5/dist-packages/lantern/data/__init__.py in <module>       1 from .data_cufflinks import getCFData       2 from .data_sklearn import getSKData ----> 3 from .other import person, people, company, companies, ticker, currency, trades, superstore       4        5 # scikit learn  /usr/local/lib/python3.5/dist-packages/lantern/data/other.py in <module>       2 import pandas as pd       3 import string ----> 4 import mimesis       5 import finance_enums       6 from faker import Faker  /usr/local/lib/python3.5/dist-packages/mimesis/__init__.py in <module>       8 """       9  ---> 10 from mimesis.providers import *      11       12 __all__ = [  /usr/local/lib/python3.5/dist-packages/mimesis/providers/__init__.py in <module>       8 from mimesis.providers.choice import Choice       9 from mimesis.providers.clothing import Clothing ---> 10 from mimesis.providers.cryptographic import Cryptographic      11 from mimesis.providers.code import Code      12 from mimesis.providers.date import Datetime  /usr/local/lib/python3.5/dist-packages/mimesis/providers/cryptographic.py in <module>       4        5 import hashlib ----> 6 import secrets       7 import uuid       8   ImportError: No module named 'secrets' </pre>    <span style="color: #666699;">奮力再跳!</span> <h1 class="public "><span style="color: #808080;"><span class="author"><a class="url fn" style="color: #808080;" href="https://github.com/scaleway" rel="author" data-hovercard-type="organization" data-hovercard-url="/orgs/scaleway/hovercard">scaleway</a></span><span class="path-divider">/</span><strong><a style="color: #808080;" href="https://github.com/scaleway/python2-secrets" data-pjax="#js-repo-pjax-container">python2-secrets</a></strong></span></h1> <span style="color: #808080;"><span class="text-gray-dark mr-2">Backport python3.6 secrets to python2 </span><a style="color: #808080;" href="https://pypi.org/project/python2-secrets/" rel="nofollow">https://pypi.org/project/python2-secr…</a></span> <h1><span style="color: #ff9900;">Secrets backport</span></h1> <span style="color: #ff9900;">Backport of Python 3.6's <a style="color: #ff9900;" href="https://docs.python.org/3/library/secrets.html" rel="nofollow">secrets</a> module for Python 2.7, 3.4 and 3.5.</span>    <pre class="lang:default decode:true ">rock64@rock64:~ git clone https://github.com/scaleway/python2-secrets
Cloning into 'python2-secrets'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 84 (delta 6), reused 13 (delta 5), pack-reused 66
Unpacking objects: 100% (84/84), done.
rock64@rock64:~cd python2-secrets/ rock64@rock64:~/python2-secrets sudo python3 setup.py install
running install
running bdist_egg
running egg_info
creating python2_secrets.egg-info
writing python2_secrets.egg-info/PKG-INFO
writing top-level names to python2_secrets.egg-info/top_level.txt
writing dependency_links to python2_secrets.egg-info/dependency_links.txt
writing manifest file 'python2_secrets.egg-info/SOURCES.txt'
reading manifest file 'python2_secrets.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'python2_secrets.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-aarch64/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/secrets
copying secrets/secrets.py -> build/lib/secrets
copying secrets/__init__.py -> build/lib/secrets
creating build/bdist.linux-aarch64
creating build/bdist.linux-aarch64/egg
creating build/bdist.linux-aarch64/egg/secrets
copying build/lib/secrets/secrets.py -> build/bdist.linux-aarch64/egg/secrets
copying build/lib/secrets/__init__.py -> build/bdist.linux-aarch64/egg/secrets
byte-compiling build/bdist.linux-aarch64/egg/secrets/secrets.py to secrets.cpython-35.pyc
byte-compiling build/bdist.linux-aarch64/egg/secrets/__init__.py to __init__.cpython-35.pyc
creating build/bdist.linux-aarch64/egg/EGG-INFO
copying python2_secrets.egg-info/PKG-INFO -> build/bdist.linux-aarch64/egg/EGG-INFO
copying python2_secrets.egg-info/SOURCES.txt -> build/bdist.linux-aarch64/egg/EGG-INFO
copying python2_secrets.egg-info/dependency_links.txt -> build/bdist.linux-aarch64/egg/EGG-INFO
copying python2_secrets.egg-info/top_level.txt -> build/bdist.linux-aarch64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/python2_secrets-1.0.6-py3.5.egg' and adding 'build/bdist.linux-aarch64/egg' to it
removing 'build/bdist.linux-aarch64/egg' (and everything under it)
Processing python2_secrets-1.0.6-py3.5.egg
Copying python2_secrets-1.0.6-py3.5.egg to /usr/local/lib/python3.5/dist-packages
Adding python2-secrets 1.0.6 to easy-install.pth file

Installed /usr/local/lib/python3.5/dist-packages/python2_secrets-1.0.6-py3.5.egg
Processing dependencies for python2-secrets==1.0.6
Finished processing dependencies for python2-secrets==1.0.6

 

哪知道燈籠找到沒?

rock64@rock64:~$ ipython3
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import lantern as l                                                     

In [2]: