"ImportError: No module named BeautifulSoup" error even after installation

Jerry Carson picture Jerry Carson · Apr 9, 2014 · Viewed 8.1k times · Source

I'm running into the following error:

Traceback (most recent call last):
  File "C:\Python27\files\samplefileoutput.py", line 1, in <module>
    import BeautifulSoup
ImportError: No module named BeautifulSoup

when I try to run the following file:

import BeautifulSoup
f = open('c:\output.txt', 'a')
f.write('Hello World!\n')
f.close()

I thought my installation was successful. I am using a Windows 7 PC. I extracted the source tarball and then through the command line, typed "setup.py install" once I had changed the directory to the extracted BeautifulSoup folder. There didn't appear to be an error message during the install. It finished with this line:

Writing C:\Python27\Lib\site-packages\beautifulsoup4-4.3.2-py2.7.egg-info

Can anyone please provide some guidance? Thanks!

Answer

mipadi picture mipadi · Apr 9, 2014

Beautiful Soup 4's module is bs4.

from bs4 import BeautifulSoup

will work, or

import bs4

if you want to import the entire module.