1
votes

I am new to python dev and have recently installed a fresh, 64-bit version of anaconda (with python v. 2.7.12) yesterday (https://www.continuum.io/downloads#windows) on my windows 8 machine. I immediately launched the Jupyter Notebook instance that came with anaconda and expected that I be able to use BeautifulSoup. Upon executing this line in my notebook.ipynb file: from bs4 import BeautifulSoup I received an ImportError:

ImportError                               Traceback (most recent call last)
<ipython-input-12-cbb98e44f096> in <module>()
      9 #from yelp.oauth1_authenticator import Oauth1Authenticator
     10 
---> 11 from bs4 import BeautifulSoup

C:\Users\xxx\Anaconda2\lib\site-packages\bs4\__init__.py in <module>()
     33 import warnings
     34 
---> 35 from .builder import builder_registry, ParserRejectedMarkup
     36 from .dammit import UnicodeDammit
     37 from .element import (

C:\Users\xxx\Anaconda2\lib\site-packages\bs4\builder\__init__.py in <module>()
    313 # to take precedence over html5lib, because it's faster. And we only
    314 # want to use HTMLParser as a last result.
--> 315 from . import _htmlparser
    316 register_treebuilders_from(_htmlparser)
    317 try:

C:\Users\xxx\Anaconda2\lib\site-packages\bs4\builder\_htmlparser.py in <module>()
      8     ]
      9 
---> 10 from HTMLParser import HTMLParser
     11 
     12 try:

ImportError: cannot import name HTMLParser

What I've tried:

  • pip install HTMLParser
  • pip install bs4
  • Uninstalling and installing beautifulsoup4 and beautifulsoup packages available in the anaconda navigator.
  • conda install HTMLParser --> resulted in package not found on anaconda repos error
  • conda install bs4 --> resulted in package not found on anaconda repos error

I have been trying to get this set up working without virtual environments in the notebook. I thought it would be possible to get it working with the root env.

Any help with this issue would be much appreciated!

1
That's odd... HTMLParser should be in the standard library for Python 2.2+, and would only be renamed in Python 3 to html.parser. - user824425
Note: I've uninstalled all versions of python (2.7.12 and 3.5) before installing anaconda. - miniscem

1 Answers

0
votes

I just restarted my PC and Jupyter Notebook detected the HTMLParser module. Not sure what I did to actually fix it - but I'm guessing the answer is one of the following steps I listed in my original question then restarting and launching Jupyter again.