본문 바로가기
개발일지/Pandas

pandas read_html 기능오류 (ImportError: html5lib not found, please install it)

by 개발에정착하고싶다 2022. 6. 13.
320x100

원래 입력되어있던것은

 

df = pd.read_html(str(table))
bitcoin = df[0]
bitcoin.head()

였다.

 

하지만 이에 대해서 에러가 뜬다.

 

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
c:\Users\danie\Documents\ds_study\source_code\05. forecast.ipynb Cell 110' in <cell line: 1>()
----> 1 df = pd.read_html(str(table))
      2 bitcoin = df[0]
      3 bitcoin.head()

File c:\Users\danie\anaconda3\envs\ds_study\lib\site-packages\pandas\util\_decorators.py:311, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
    305 if len(args) > num_allow_args:
    306     warnings.warn(
    307         msg.format(arguments=arguments),
    308         FutureWarning,
    309         stacklevel=stacklevel,
    310     )
--> 311 return func(*args, **kwargs)

File c:\Users\danie\anaconda3\envs\ds_study\lib\site-packages\pandas\io\html.py:1113, in read_html(io, match, flavor, header, index_col, skiprows, attrs, parse_dates, thousands, encoding, decimal, converters, na_values, keep_default_na, displayed_only)
   1109 validate_header_arg(header)
   1111 io = stringify_path(io)
-> 1113 return _parse(
   1114     flavor=flavor,
   1115     io=io,
   1116     match=match,
   1117     header=header,
   1118     index_col=index_col,
   1119     skiprows=skiprows,
   1120     parse_dates=parse_dates,
   1121     thousands=thousands,
   1122     attrs=attrs,
   1123     encoding=encoding,
   1124     decimal=decimal,
   1125     converters=converters,
   1126     na_values=na_values,
   1127     keep_default_na=keep_default_na,
   1128     displayed_only=displayed_only,
   1129 )

File c:\Users\danie\anaconda3\envs\ds_study\lib\site-packages\pandas\io\html.py:915, in _parse(flavor, io, match, attrs, encoding, displayed_only, **kwargs)
    913 retained = None
    914 for flav in flavor:
--> 915     parser = _parser_dispatch(flav)
    916     p = parser(io, compiled_match, attrs, encoding, displayed_only)
    918     try:

File c:\Users\danie\anaconda3\envs\ds_study\lib\site-packages\pandas\io\html.py:864, in _parser_dispatch(flavor)
    862 if flavor in ("bs4", "html5lib"):
    863     if not _HAS_HTML5LIB:
--> 864         raise ImportError("html5lib not found, please install it")
    865     if not _HAS_BS4:
    866         raise ImportError("BeautifulSoup4 (bs4) not found, please install it")

ImportError: html5lib not found, please install it

 

쉽게 보자면 import 되어있는 html5lib을 못찾겠으니, 설치해달라.

라는것이다.

 

방금 전의 코드는 분명 pandas 내부모듈로써 작동하는것을 확인했지만,

애초에 크롤링해온 url을 변경하고 다시실행을 해보니 이런 오류가 떴다.

html5lib을 다운받아주었다.

 

여전히 똑같은 에러가 뜬다.

 

순차적으로 다시

 

df = pd.read_html(str(table))
df

이렇게 실행해주었고

 

그다음엔

df = pd.read_html(str(table))
df[0]

이렇게 실행해주었고

 

마지막으론

 

다시 애초의 코드처럼

 

df = pd.read_html(str(table))
bitcoin = df[0]
bitcoin.head()

라고 실행해주었다.

결과는 잘 작동된다.

 

Timestamp	Open	High	Low	Close	Volume (BTC)	Volume (Currency)	Weighted Price
0	2020-06-14 00:00:00	9478.93	9479.59	9235.01	9329.99	3477.25	3.258155e+07	9369.91
1	2020-06-15 00:00:00	9329.99	9505.40	8900.00	9435.15	11765.11	1.080923e+08	9187.52
2	2020-06-16 00:00:00	9435.41	9596.31	9374.90	9530.30	6864.22	6.515525e+07	9492.01
3	2020-06-17 00:00:00	9530.62	9566.53	9230.32	9461.29	5902.37	5.563403e+07	9425.72
4	2020-06-18 00:00:00	9459.82	9478.69	9250.00	9374.78	3997.01	3.755364e+07	9395.43

이렇게.

 

솔직히 어이가 없다.

파이썬 구조상 첫째줄, 왼쪽 기준부터 코드가 실행되면서 내림차순으로 코드진행이 될텐데

1,2,3의 단계로 분할해서 진행할때는 작동이 되지만

똑같은 코드를 1,2,3 한번에 썼을땐 실행이 안되고 에러가 뜨는경우가.

 

당연하게도 이런류의 에러는 구글링해도 무용지물이다.

에러 메세지에는 html5lib을 받아주라고 하는데 그거 구글링한다고 해결될까?

무지성으로 구글링 하라고 하는것도 문제가 있다.

300x250