0

I am running a batch file which runs my python code through the command prompt. However, when running the code it gives me the following error:

 from html_table_parser import HTMLTableParser
 ModuleNotFoundError: No module named 'html_table_parser'

However, when running my code through Jupyter-notebooks its works just fine. Is it because it isn't properly downloaded. My python.exe is found in Anaconda.

My code is the following

import urllib.request
from pprint import pprint
from html_table_parser import HTMLTableParser
import datetime
# pretty-print python data structures 
from pprint import pprint   
# for parsing all the tables present  on the website 


# for converting the parsed data in a 
# pandas dataframe 
import pandas as pd 
from bs4 import BeautifulSoup


 # Opens a website and read its 
 # binary contents (HTTP Response Body) 
  def url_get_contents(url): 

   # Opens a website and read its 
  # binary contents (HTTP Response Body) 

  #making request to the website 
  req = urllib.request.Request(url=url) 
   f = urllib.request.urlopen(req) 

   #reading contents of the website 
   return f.read() 
    xhtml = url_get_contents("https://en.wikipedia.org/wiki/Searching").decode('utf-8') 

  # Defining the HTMLTableParser object 
  p = HTMLTableParser() 

 content = urllib.request.urlopen("https://en.wikipedia.org/wiki/Searching")
  read_content = content.read()
Monica
  • 11
  • 3
  • you need to make sure that `html_table_parser` is available on python's path. Look `sys.path`. – Z4-tier Jan 05 '21 at 21:05
  • Does this answer your question? [Expand Python Search Path to Other Source](https://stackoverflow.com/questions/3144089/expand-python-search-path-to-other-source) – Z4-tier Jan 05 '21 at 21:07
  • no, those don't help because it works in jupyter notebook – Monica Jan 05 '21 at 21:31
  • Maybe because your install of the package is associated with anaconda folders and is not found where command prompt execution looks. I had this where I actually had two python installs of which one was anaconda. Packages I loaded via anaconda were not being found from command line so I was having to pip install the packages not found via command line as well. I think this is a bad thing to do but I didn't know any better. Perhaps this is the problem you are having? – QHarr Jan 06 '21 at 03:35
  • `ModuleNotFoundError` means the import system can't find your module. If an import works using one python interpreter on a system and then doesn't work using a different python interpreter on the same system, it means the importer systems are not set up to look in the same places. To fix it, you need to look at where the working interpreter is looking, and make the non-working interpreter look in those same places. That one happens to be jupyter notebook is irrelevant. – Z4-tier Jan 06 '21 at 05:10
  • I got it to work by doing pip install all the programs it says its missing as suggested. Thanks – Monica Jan 06 '21 at 16:57

1 Answers1

0
pip install html-table-parser-python3

I have solved it by installing the above package.

Syscall
  • 19,327
  • 10
  • 37
  • 52