如何解决“module”对象没有属性“_base”的问题?

8
我想运行位于https://github.com/kirkthaker/investopedia-trading-api的Investopedia API。
我编写了以下脚本:
from investopedia import *
client = Account("emailaddress","password")

status = client.get_portfolio_status()
print status.account_val
print status.buying_power
print status.cash
print status.annual_return

我运行py -2.7 setup.py install命令来安装所有依赖模块。
我收到以下错误信息:
Traceback (most recent call last):
File "C:/Users/Z/PycharmProjects/investopedia/test.py", line 1, in <module>
    from investopedia import *
  File "C:\Users\Z\PycharmProjects\investopedia\investopedia.py", line 4, in <module>
    from bs4 import BeautifulSoup
  File "C:\Users\Z\AppData\Local\Enthought\Canopy\User\lib\site-packages\bs4\__init__.py", line 29, in <module>
    from .builder import builder_registry
  File "C:\Users\Z\AppData\Local\Enthought\Canopy\User\lib\site-packages\bs4\builder\__init__.py", line 297, in <module>
    from . import _html5lib
  File "C:\Users\Z\AppData\Local\Enthought\Canopy\User\lib\site-packages\bs4\builder\_html5lib.py", line 57, in <module>
    class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):
AttributeError: 'module' object has no attribute '_base'

你知道如何解决这个问题吗?


你在安装Investopedia API之前是否已经安装了BeautifulSoup依赖? - martineau
是的,我使用了“py-2.7 setup.py install”来安装BeautifulSoup4,但我已在下面发布了我的解决方案。 - hasanzuav
2个回答

23

使用以下方法解决了问题

pip2.7 install --upgrade beautifulsoup4
pip2.7 install --upgrade html5lib

现在运作得非常好。


我建议您编辑您的答案并说明为什么执行这些操作是必要的,以更好地帮助其他遇到类似问题的人。 - martineau
说实话,我不确定为什么这是必要的。我只是在尝试这篇文章中的东西:https://dev59.com/fFoT5IYBdhLWcg3wjwB- - hasanzuav
1
pip install -help -> --upgrade 选项: "将所有指定的包升级到最新可用版本。依赖关系的处理取决于使用的升级策略。" 所以看起来问题是你没有两个包的最新版本,即使安装了旧版本。 - martineau

0

我通过使用conda解决了这个问题

conda install beautifulsoup4
conda install html5lib

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接