简体   繁体   中英

Receving an error when trying to use the pandas read_html function

I'm really new to python and pandas so I could be making a simple mistake.

I'm trying to run the code below:

import quandl
import pandas as pd

df3 = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
print(df3)

I have installed pandas as well quandl through pip. When I run the code I get the following error:

Traceback (most recent call last):
File "C:\Python27\FunwithQuandl.py", line 14, in <module>
df3 = pd.read_html('https://simple.wikipedia.org /wiki/List_of_U.S._states')
File "C:\Python27\lib\site-packages\pandas\io\html.py", line 874, in read_html
parse_dates, tupleize_cols, thousands, attrs, encoding)
File "C:\Python27\lib\site-packages\pandas\io\html.py", line 726, in _parse
parser = _parser_dispatch(flav)
File "C:\Python27\lib\site-packages\pandas\io\html.py", line 685, in _parser_dispatch
raise ImportError("lxml not found, please install it")
ImportError: lxml not found, please install it

I then tried installing lxml via command prompt and pip and I got a few errors:

Cannnot open include file: 'libxml/xpath.h': No such file or directory

Could not find function xmlCheckVersion in library libxm12. Is libxml2 installed?

error: command 'CL\\User\\...Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2

I even tried suggestions on this from this thread :

such as

"install lxml from lfd.uci.edu/~gohlke/pythonlibs/#lxml for your python version. It's a precompiled WHL with required modules/dependencies.

The site lists several packages, when eg using Win32 Python 2.7, use lxml-3.6.1-cp27-cp27m-win32.whl."

I have downloaded the whl file from the site suggested but I can't seem to install it. I have tried using pip and typing out the name of the file but the file isn't being recognized via pip.

I am using Python 2.7 and Windows 7 professional

Thanks for you help.

I fixed the problem. I moved the file that I wanted to install from Downloads to LocalDisk/Users/My_name . Inside the right directory, PIP was able to locate and install it for some reason. Thanks for the responses.

I had a similar problem with configuring pandas, and the reason that for the same, I think, was that I am on a windows x64 machine, whereas my pip package was installing win32 .whl files.

I was really upset with it, until I found https://www.lfd.uci.edu/~gohlke/pythonlibs/ This is the site where I was able to get winx64 compatible modules, which I had used later with pip locally to install my packages, then the issue got resolved. (Please Note: The link provided has Python packages for Windows only).

I hope it helps.

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