LoginSignup
0
0

More than 3 years have passed since last update.

SAS Viyaのトライアル環境で html5lib を追加する

Posted at

SAS ViyaはAI開発環境です。無料で使えるトライアル版を提供しています。様々なデータをデータソースとして取り込めるのですが、その中にHTMLテーブルを読み込める機能があります。しかし、デフォルトのまま実行すると、html5libがないというエラーになります。

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-4-8d2857382349> in <module>()
----> 1 htmldmh = dmh.HTML('./FDIC_ FailedBankList.htm', 'index=0')

/opt/sasinside/anaconda3/lib/python3.6/site-packages/swat/cas/datamsghandlers.py in __init__(self, path, index, nrecs, transformers, **kwargs)
    865 
    866     def __init__(self, path, index=0, nrecs=1000, transformers=None, **kwargs):
--> 867         super(HTML, self).__init__(pd.read_html(path, **kwargs)[index],
    868                                    nrecs=nrecs, transformers=transformers)
    869 
  :
/opt/sasinside/anaconda3/lib/python3.6/site-packages/pandas/io/html.py in _parser_dispatch(flavor)
    666     if flavor in ('bs4', 'html5lib'):
    667         if not _HAS_HTML5LIB:
--> 668             raise ImportError("html5lib not found, please install it")
    669         if not _HAS_BS4:
    670             raise ImportError(

ImportError: html5lib not found, please install it

そしてhtml5libをインストールしようとするのですが、テスト環境ではサーバから外部環境へアクセスが禁止されており、ネットワーク接続ができません。

!pip install html5lib
Collecting html5lib
    :
  Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f625ced3320>, 'Connection to pypi.python.org timed out. (connect timeout=15)')': /simple/html5lib/
  Could not find a version that satisfies the requirement html5lib (from versions: )
No matching distribution found for html5lib

それを回避する方法を紹介します。

ローカルファイルをアップロードする

まず必要なのは html5lib と、さらに html5lib に依存する webencodings です。どちらもPyPIからダウンロードできます。

そしてダウンロードしたファイルをJupyterの画面でアップロードします。

Screenshot_ 2019-05-25 13.26.00.png

インストールする

アップロードしたら、ファイルを解凍してインストールします。この時、 --user をつけてユーザ環境下にインストールします。インストールは依存がないwebencodingsを最初に行います。

!tar xfz webencodings-0.5.1.tar.gz
!pip install ./webencodings-0.5.1 --user

!tar xfz html5lib-1.0.1.tar.gz
!pip install ./html5lib-1.0.1 --user

ライブラリの読み込みパスを追加する

ライブラリは ~/.local/lib/python3.6/site-packages/ にインストールされますので、このパスをライブラリの読み込みパスに追加します。 dev は皆さんのユーザ名です。

import sys
sys.path.append("/home/dev/.local/lib/python3.6/site-packages")

これでHTMLテーブルが読み込めるようになります。

from swat.cas import datamsghandlers as dmh
htmldmh = dmh.HTML('./FDIC_ FailedBankList.htm')

まとめ

トライアル環境では他にも幾つかの制限はありますが、殆どの試用はできるようになっています。ぜひSAS Viyaを使ってAI/機械学習を体験してください。

SAS for Developers | SAS

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0