错误导入BeautifulSoup - 冲突与Python版本(Error importing B

2019-08-31 22:48发布

我用命令安装BeautifulSoup:

sudo easy_install BeautifulSoup4

我得到的消息:

Searching for BeautifulSoup4
Best match: beautifulsoup4 4.1.3
Processing beautifulsoup4-4.1.3-py2.6.egg
beautifulsoup4 4.1.3 is already the active version in easy-install.pth

Using /Library/Python/2.6/site-packages/beautifulsoup4-4.1.3-py2.6.egg
Processing dependencies for BeautifulSoup4
Finished processing dependencies for BeautifulSoup4

我试图导入BeautifulSoup库。

>>> from BeautifulSoup import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named BeautifulSoup

要么:

>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bs4

我的Python版本是:

python --version
Python 2.7.3

编辑

我明白那个:

Using /Library/Python/2.6/site-packages/beautifulsoup4-4.1.3-py2.6.egg

可能意味着存在的Python版本之间有冲突

我怎么能有这样的模块注册? 谢谢

Answer 1:

它应该是,

from bs4 import BeautifulSoup


Answer 2:

做这个:

  • easy_install pip
  • 当完成后,重新启动,并在类型pip install beautifulsoup4 。 这应该工作。

请确保您有它作为一个模块pip list ,如果你看到美丽的汤作为输出,那么,你有它的工作。



Answer 3:

经过一番研究,我发现,这个解决这一问题:

pip uninstall BeautifulSoup4

将卸载包是:

/Library/Python/2.6/site-packages/

和:

easy_install-2.7 BeautifulSoup4

将成功安装包:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/

我检查的过程中也具有相同问题的一些其他软件包和它的作品。



文章来源: Error importing BeautifulSoup - Conflict with Python version