本文介绍了BeautifulSoup4 藏在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了 sudo pip install BeautifulSoup4 并得到了非常乐观的回应:

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

但是当我尝试在脚本中使用 import BeautifulSoup4from BeautifulSoup4 import BeautifulSoup4 时,python 说没有该名称的模块.

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

更新:pip 告诉我 beautifulsoup4 in/usr/local/lib/python2.6/dist-packages 但我运行的是 2.7.2+(和 print sys.path 看到 2.7 个路径)......所以现在我需要弄清楚为什么 pip 把东西放在错误的地方.

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.

推荐答案

尝试 import bs4.不幸的是,PyPI 包名称和导入名称之间没有对应关系.之后,类名与之前相同,例如.soup = bs4.BeautifulSoup(doc) 会起作用.

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.

如果仍然不起作用,请再次尝试 pip install 并记下软件包安装的路径.然后在你的 python 控制台中运行 import sysprint sys.path 以确保路径在那里.

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.

您可能需要明确指定pip-2.7 或切换到easy_install(或easy_install-2.7)

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

这篇关于BeautifulSoup4 藏在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:06