问题描述
我做了 sudo的点子安装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..
但是当我尝试使用进口BeautifulSoup4
或从BeautifulSoup4进口BeautifulSoup4
在脚本中,蟒蛇说没有该名称的模块。
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
告诉我/usr/local/lib/python2.6/dist-packages beautifulsoup4
但我运行2.7.2+(和打印的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.
推荐答案
尝试进口BS4
。这是不幸的还有PyPI将包名和导入名之间没有对应关系。在这以后,类名是相同的如前。 汤= 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重新安装
并注意路径包安装。然后在你的Python控制台运行进口SYS
和打印的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被藏匿在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!