Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

python - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...