8

I have tried everything here: How can I install the Beautiful Soup module on the Mac?

Installation seems to work (getting correct output during install) from both the traditional way to install and also using easy_install but when I use:

from bs4 import BeautifulSoup

the interpreter says no such module exists.

What should I look at first to troubleshoot this?

Community
  • 1
  • 1
Fusilli Jerry
  • 745
  • 4
  • 8
  • 16
  • 2
    are you sure that you use the correct version of python interpreter (if several are installed on your computer)? try calling your script with python2.6, python2.7, etc. – btel Nov 11 '12 at 15:41

3 Answers3

6

To see all the packages you have installed, you can run the following in a interpreter:

>>> help('modules')

That will list for you all the modules you have installed. Look for bs4 in the list (which seems to be alphabetical). Another option is to issue at your prompt:

$ python -c "help('modules')" | grep bs4

If nothing comes up, or you cannot find it in the list, the module is not installed.

To install it, I used sudo pip install bs4. You may need to run sudo easy_install pip first to get pip. Also note the use of sudo, as this may make a difference.

And I'm running 10.8 build version 12C60.

Whymarrh
  • 13,139
  • 14
  • 57
  • 108
  • Thank you - very useful. I can confirm that the module is installed and for some reason it is allowing me to import it now. Very strange. For some reason after I install new modules (among other things) my machine won't update. I let the machine 'sleep' and when I come back to it they are working. Is there some sort of 'update' command or refresh that must be done after installing new packages? – Fusilli Jerry Nov 12 '12 at 02:50
  • Not that I know of, but you can always run the `help()` command after an install to make sure it worked. – Whymarrh Nov 12 '12 at 03:08
0

I have an uggly solutions which works for me:

try:
    from bs4 import BeautifulSoup as bs
except ImportError:
    from BeautifulSoup import BeautifulSoup as bs

after what, I call everything with bs prefix.

Aif
  • 11,015
  • 1
  • 30
  • 44
0

I've had the same issue. bs4 is installed but it wasn't showing up in help(modules).

I don't know if this will work for others, but I had the same issue with openCV and solved it by adding the following before trying to load the package. It worked for openCV and it just worked for bs4:

import sys
sys.path.append('/usr/local/lib/python3.6/site-packages')
Isaac
  • 215
  • 2
  • 15