Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is BeautifulSoup4 hiding?

I did sudo pip install BeautifulSoup4 and got an awfully optimistic response:

Downloading/unpacking beautifulsoup4
  Running setup.py egg_info for package beautifulsoup4
Installing collected packages: beautifulsoup4
  Running setup.py install for beautifulsoup4
Successfully installed beautifulsoup4
Cleaning up..

but when I try to use import BeautifulSoup4 or from BeautifulSoup4 import BeautifulSoup4 in a script, python says there's no module by that name.

> import BeautifulSoup
ImportError: No module named BeautifulSoup

Update: pip tells me beautifulsoup4 in /usr/local/lib/python2.6/dist-packages but I'm running 2.7.2+ (and print sys.path sees 2.7 paths) ... so now I need to figure out why pip is putting things in the wrong place.

like image 352
Amanda Avatar asked Oct 15 '12 19:10

Amanda


People also ask

How do you get a beautifulsoup4?

Beautiful Soup 4 is published through PyPi, so if you can't install it with the system packager, you can install it with easy_install or pip . The package name is beautifulsoup4 . Make sure you use the right version of pip or easy_install for your Python version (these may be named pip3 and easy_install3 respectively).

Is beautifulsoup4 the same as Beautifulsoup?

The official name of PyPI's Beautiful Soup Python package is beautifulsoup4 . This package ensures that if you type pip install bs4 by mistake you will end up with Beautiful Soup .

What is beautifulsoup4 in Python?

Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. It commonly saves programmers hours or days of work.

How do I import from beautifulsoup4?

For Windows... Go to start menu type cmd right click on cmd icon click run as administrator then type pip install beautifulsoup4. It likely will fail to install correctly if you fail to do the above step as even though your windows user is an admin account it does not run all apps as administrator.


1 Answers

Try import bs4. It's unfortunate there's no correspondence between PyPI package name and import name. After that the class names are the same as before eg. soup = bs4.BeautifulSoup(doc) will work.

If that still doesn't work, try pip install again and note the path to the package install. Then in your python console run import sys and print sys.path to make sure that the path is there.

You might need to explicitly specify pip-2.7 or switch to easy_install (or easy_install-2.7)

like image 163
Colonel Panic Avatar answered Oct 16 '22 04:10

Colonel Panic