0

I am working with Jupyter Notebook and have python 2.7 and 3.4 installed on it. I installed BeautifulSoup before importing it by this line:

pip install beautifulsoup4

The problem is that it is installed on python 2.7 while beautifulsoup4 is working on python 3.4. I also tried pip3 install beautifulsoup4 to install it on python 3 but the problem is still there and when i do this line: from bs4 import BeautifulSoup i again get the error below:

Error:

ImportError: cannot import name _htmlparser

Does anyone know how i can solve this problem since it appears beautifulsoup4 should be installed on python 3 while mine get installed in python 2??

user8034918
  • 441
  • 1
  • 9
  • 20
  • 1
    Possible duplicate of [ImportError: cannot import name 'HTMLAwareEntitySubstitution'](https://stackoverflow.com/questions/40856104/importerror-cannot-import-name-htmlawareentitysubstitution) – Mark Nov 24 '17 at 07:49
  • @Mark Actually my problem is different. And by doing the command "pip install --upgrade --force-reinstall beautifulsoup4" , my problem gets worse and i will get this error: AttributeError: type object 'HTMLAwareEntitySubstitution' has no attribute 'preserve_whitespace_tags' – user8034918 Nov 24 '17 at 08:00
  • No, you just fix _htmlparser error and move to your next error. – Mark Nov 24 '17 at 08:12

1 Answers1

0

Assuming you have added both versions to path you should rename the Python 2.7 version and Python 3.4 version to something else (ie pip27 and pip34). I also suggest you not only rename the pip but python interpreter as well (like python27 and python34.

Second since you have two Python versions you will need to call from command line (if you do not already). It might be that you have installed beautifulsoup correctly but you are using the wrong Python interpreter.

To run Python from command line use:

pythonXX file.py

I used pythonXX because I assume you have renamed each interpreter to distinguish the two versions.

Xantium
  • 11,201
  • 10
  • 62
  • 89