1

I installed BeautifulSoup with the command:

sudo easy_install BeautifulSoup4

I got the message:

Searching for BeautifulSoup4
Best match: beautifulsoup4 4.1.3
Processing beautifulsoup4-4.1.3-py2.6.egg
beautifulsoup4 4.1.3 is already the active version in easy-install.pth

Using /Library/Python/2.6/site-packages/beautifulsoup4-4.1.3-py2.6.egg
Processing dependencies for BeautifulSoup4
Finished processing dependencies for BeautifulSoup4

I'm trying to import the BeautifulSoup lib.

>>> from BeautifulSoup import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named BeautifulSoup

or:

>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bs4

My Python version is:

python --version
Python 2.7.3

EDIT

I understand that:

Using /Library/Python/2.6/site-packages/beautifulsoup4-4.1.3-py2.6.egg

Could mean that there is a conflict between the versions of Python

How can I have this module registered? Thanks

maxdangelo
  • 3,063
  • 5
  • 21
  • 25

4 Answers4

4

It should be,

from bs4 import BeautifulSoup
thavan
  • 2,409
  • 24
  • 32
  • The result is the same: ImportError: No module named bs4 – maxdangelo Apr 23 '13 at 16:13
  • @maxdangelo Do you have two different version of python installed in your machine? – thavan Apr 24 '13 at 09:56
  • I don't think so, I've updated python from 2.6 (That is coming by default in my macos 10.6.8 installation) to 2.7. – maxdangelo Apr 24 '13 at 10:02
  • 1
    @maxdangelo search for the file BeautifulSoup.py in your system. It should be there in your dist-packages or site-packages directory. – thavan Apr 24 '13 at 10:09
  • there is not a file with this name in my system. – maxdangelo Apr 29 '13 at 09:53
  • 1
    @maxdangelo Please try to re-install it with pip instead of easy_install. "sudo pip install BeautifulSoup". To use pip you need to install setup-tools module. – thavan Apr 29 '13 at 11:50
  • Requirement already satisfied (use --upgrade to upgrade): BeautifulSoup4 in /Library/Python/2.6/site-packages/beautifulsoup4-4.1.3-py2.6.egg I unfortunately think that in my installation there is a conflict between the original version of Python coming with OS 10.6 and the 2.7.3 that I've installed. I'm planning to delete both the version and install a clean one. Thanks for the support. – maxdangelo Apr 30 '13 at 11:43
1

Do this:

  • easy_install pip
  • When that is done, restart, and type in pip install beautifulsoup4. That should work.

Make sure that you have it as a module with pip list, if you see Beautiful Soup as an output, then yes, you have it working.

Games Brainiac
  • 80,178
  • 33
  • 141
  • 199
0

After some research I discovered that this solve the issue:

pip uninstall BeautifulSoup4

will uninstall the package that is in:

/Library/Python/2.6/site-packages/

And:

easy_install-2.7 BeautifulSoup4

will successfully install the package in:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/

I've checked the process also with some other packages having the same issues and it works.

maxdangelo
  • 3,063
  • 5
  • 21
  • 25
-3

You have to also

pip install bs4

and use

>>> from bs4 import BeautifulSoup
S.B
  • 13,077
  • 10
  • 22
  • 49
Peter
  • 1