Ama*_*nda 17 python pip beautifulsoup
我做了sudo pip install BeautifulSoup4并得到了非常乐观的回应:
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..
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用import BeautifulSoup4或from BeautifulSoup4 import BeautifulSoup4在脚本中时,python说这个名称没有模块.
> import BeautifulSoup
ImportError: No module named BeautifulSoup
Run Code Online (Sandbox Code Playgroud)
更新:pip告诉我,beautifulsoup4 in /usr/local/lib/python2.6/dist-packages但我正在运行2.7.2+(并print sys.path看到2.7路径)...所以现在我需要弄清楚为什么pip把东西放在错误的地方.
Col*_*nic 35
试试import bs4.不幸的是,PyPI包名和导入名之间没有对应关系.之后,类名与之前相同.soup = bs4.BeautifulSoup(doc)将工作.
如果仍然无效,请pip install再次尝试并注意包安装的路径.然后在你的python控制台运行import sys并print sys.path确保路径在那里.
您可能需要明确指定pip-2.7或切换到easy_install(或easy_install-2.7)