python - 萨吉马斯的 BeautifulSoup4

标签 python beautifulsoup pip sage

我正在尝试使用 BS4 执行网页抓取,然后使用 Sage 6.2(在 Lion 10.7.5 中)中的结果进行一些代数运算。我假设/Applications/Sage-6.2.app/Contents/Resources/sage/sage -i beautifulsoup4可以,但结果是

Attempting to download package beautifulsoup4
>>> Checking online list of optional packages.
[Traceback (most recent call last):
  File "<stdin>", line 35, in <module>
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 240, in retrieve
    fp = self.open(url, data)
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 208, in open
    return getattr(self, name)(url)
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 359, in open_http
    return self.http_error(url, fp, errcode, errmsg, headers)
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 376, in http_error
    return self.http_error_default(url, fp, errcode, errmsg, headers)
  File "<stdin>", line 17, in http_error_default
IOError: [Errno 404] Not Found: '//www.sagemath.org/spkg/optional/list'
Error: failed to download http://www.sagemath.org/spkg/optional/list, aborting

接下来,我尝试了/Applications/Sage-6.2.app/Contents/Resources/sage/sage -sh <<< "easy_install --verbose pip"通过 pip 获取 bs4。就成功了;然而/Applications/Sage-6.2.app/Contents/Resources/sage/local/bin/pip2.7 install beautifulsoup4失败并显示错误消息

Traceback (most recent call last):
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 548, in <module>
    main()
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 530, in main
    known_paths = addusersitepackages(known_paths)
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 266, in addusersitepackages
    user_site = getusersitepackages()
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 241, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 231, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sysconfig.py", line 516, in get_config_var
    return get_config_vars().get(name)
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sysconfig.py", line 449, in get_config_vars
    import re
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/re.py", line 105, in <module>
    import sre_compile
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_compile.py", line 14, in <module>
    import sre_parse
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_parse.py", line 17, in <module>
    from sre_constants import *
  File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_constants.py", line 18, in <module>
    from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT

接下来,我尝试升级到 Sage 6.6。一切都很顺利,bs4 的安装也很顺利。但是,当我打开笔记本时,我无法运行代码单元格,因为“Shift-Enter”命令仅注册为“Enter”并给了我一个新行而不是评估代码。此外,没有“评估”按钮。任何解决这些问题的建议将不胜感激。

最佳答案

不幸的是,Sage 改变了处理 BS 等可选包的方式,因此旧版本可能无法使用它们。不过,您随时可以去照镜子,例如 http://mirrors.mit.edu/sage/spkg/optional/下载它,并将其放入(旧 Sage 的)可选 spkg 目录中,然后尝试执行 sage -i path/to/file

关于笔记本问题,由于 jQuery 版本不同,这应该是在浏览器中进行“硬缓存重置”的问题,请参见例如here .

关于python - 萨吉马斯的 BeautifulSoup4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35249271/

相关文章:

python - BeautifulSoup4 无法正常工作,即使我已经使用 pip Linux Mint Sarah 成功安装了它

python-3.x - BeautifulSoup 发现所有表都是空的

python - 无法使用 pip 安装 openpifpaf 和 pycocotools。错误: Failed building wheel for openpifpaf/pycocotools

python - 如何安装cuML模块?

python - AlchemyAPI 编译时出错

python - Numpy,观察中变量对的频率

python - 使用 Python 将 HTML 渲染为纯文本

python - pip缓存文件夹在哪里?

python - conda 虚拟环境不适用于 pycharm

python - 如何从 python 中的日期时间字符串获取时区?