简体   繁体   中英

Installing BeautifulSoup on Mac OSX

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?

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.

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.

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM