我正在尝试使用 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/