Sagemath的BeautifulSoup4

时间:2016-02-07 03:13:46

标签: 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的安装也是如此。但是,当我打开笔记本时,我无法运行代码单元,因为&#34; Shift-Enter&#34;命令仅注册为&#34;输入&#34;并给了我一个新的行,而不是评估代码。此外,没有&#34;评估&#34;按钮。任何解决这些问题的建议都将不胜感激。

1 个答案:

答案 0 :(得分:2)

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

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